T-Group data
N-Gate Course completion
Dp[i] represents the binary number of I in 1 corresponding to the position of the course to complete the minimum number of minutes to complete the time record how it came down.
1->2^n List
(1<<n)-1 is all 1 then output can be
#include <stdio.h>#include<algorithm>#include<string.h>#include<stack>using namespacestd;#defineINF 100000000structnode{Charz[ -]; intDa,ta;} x[ -];structnode1{intTime,pa,sc,now;} dp[1<< -];BOOLCMP (node A,node b) {returnstrcmp (A.Z,B.Z) <0;} Stack<int>s;intMain () {intT; scanf ("%d",&t); while(t--) { intN; scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%s%d%d",x[i].z,&x[i].da,&X[i].ta); Sort (x,x+n,cmp); inten=1<<N; for(intI=1; i<=en;i++) {Dp[i].sc=inf; for(intj=n-1; j>=0; j--) { inttem=1<<J; if(i&tem) { intpast=i-tem; intst=dp[past].time+x[j].ta-X[j].da; if(st<0) St=0; if(st+dp[past].sc<Dp[i].sc) {Dp[i].sc=st+Dp[past].sc; DP[I].PA=past; Dp[i].now=J; Dp[i].time=dp[past].time+X[j].ta; } }}} en--; printf ("%d\n", Dp[en].sc); while(en) {s.push (Dp[en].now); En=DP[EN].PA; } while(!S.empty ()) { intnow=S.top (); printf ("%s\n", x[now].z); S.pop (); } } return 0;}
State compression HDU1074