Title Link: Doing Homework
Huge nausea. Find a night bug, found that for loop initialization actually can not replace memset. Sincere disobedience,
The AC code is attached:
1#include <stdio.h>2#include <string.h>3#include <iostream>4 using namespacestd;5 6 #defineN 167 #defineM 1<<168 #defineINF 0x3f9 intN, M;Ten intDp[m], pre[m], t[m]; One intDead[n], cost[n]; A Charname[n][ About]; - - voidPrintintt) { the if(T = =0)return; - print (pre[t]); -T-= pre[t];// - for(intI=0; i<n; ++i) { + if(T &1<<i) { - puts (name[i]); + } A } at } - - intMain () { - intT; -scanf"%d", &T); - while(t--) { inscanf"%d", &n); - for(intI=0; i<n; ++i) { toscanf"%s%d%d", Name[i], &dead[i], &cost[i]); + } - the //for (int i=0; i<m; ++i) {//can't actually replace memset ... I'm drunk, too. * //Dp[i] = 0x3f; $ // }Panax NotoginsengMemset (DP,0x3f,sizeof(DP)); -dp[0] = t[0] =0;//Initialize them =1<<N; + //memset (t, 0, sizeof (t));//about t[] Why not update to 0? Did not read,??? A the for(intI=1; i<m; ++i) {//Enumeration State + for(intj=0; j<n; ++j) { - if((I &1<< j) = =0)Continue; $ intK = i-(1<<j); $ intTempt = T[k] +Cost[j]; - //if (tempt < t[i]) continue; -T[i] =tempt; the intTcost = Dead[j] > t[i]?0: T[i]-Dead[j]; - if(Dp[k] + tcost <= dp[i]) {//from the go after enumeration, should be no equals number will be the dictionary order from small to large ah.??? WuyiDp[i] = Dp[k] +Tcost; thePre[i] =K; - } Wu } - } Aboutprintf"%d\n", dp[m-1]); $Print (M-1); - } - return 0; -}View Code
Detailed code is included:
1 /*2 Test Instructions: Gives the n (1<=n<=15) jobs, and the dealline of the job and the time it takes to complete. The work will be deducted 1 points a day after delivery. 3 Be sure to complete all tasks to minimize the score of the completion scenario. If the number of scenarios is multiple, the output dictionary is the least ordered. The job name is no longer than 100 characters. 4 5 //idea: start at the current time of 0, looking for the most urgent as the next goal to complete until all tasks are completed. 6 The current most need to complete is the Dealine-tasktime current time difference is the least. That is, you can sort by deadine-tasktime, from small to large. Complete in turn. 7 //above from unreasonable. Although it is not verified that this is not a8 9 idea: Pressure DP. Because the n maximum is 15. So use a number m,2^15 to represent the total state. When you turn binary 0 and 1 indicate that the current job is not done and done. Every state from 0 to M,Ten iterates over whether each job has completed in its current state, and if not, continues with the next job. Otherwise, compare the current state without completing the job until the job has been reduced by the time it was completed and the time it was originally required, taking the minimum. One Dp[i] = J. Indicates that the minimum time to reduce the I state is J. T_t said not clearly. See the code for details. A */ - -#include <stdio.h> the#include <string.h> -#include <iostream> - using namespacestd; - + Const intN = -, M =1<<N; - + intD[n], c[n], N; A intDp[m], pre[m], t[m]; at Chars[n][ the]; - - voidPrintintk) - { - if(k = =0)return; - print (pre[k]); inK-=Pre[k]; - for(inti =0; I < n; ++i) to if(K &1<<i) puts (s[i]); + } - the intMain () { * intT, M, cost; $scanf"%d", &T);Panax Notoginseng while(t--) { -scanf"%d", &n); the for(intI=0; i<n; ++i) { +scanf"%s%d%d", S[i], &d[i], &c[i]); A } the +Memset (DP,0x3f,sizeof(DP)); -dp[0] = t[0] =0;//the boundaries of all jobs that are not done are divided into 0 $m =1<< N;//0 to M means all states. $ - for(intI=1; i<m; ++i) {//enumerate each State - for(intj=0; j<n; ++J) {//judge the state of writing for each job did not the if((I &1<< j) = =0)//If you don't do it, - Continue;Wuyi intK = i-(1<< j);//The K-state indicates that the current I-state did not do the job J. theT[i] = T[k] + c[j];//T[i] Indicates the minimum time to take from K to I state -Cost = T[i] > d[j]? T[i]-D[J]:0;//compared to the cut-off time of the J job, the current reduction time is obtained . Wu if(Dp[k] + cost <= dp[i]) {//Judging is not to be from K to I. -Dp[i] = Dp[k] +Cost ; AboutPre[i] =K; $ } - } - } -printf"%d\n", dp[m-1]); APrint (M-1); + } the return 0; -}View Code
HDU 1074 Doing Homework-like pressure DP