Test instructions: Input T indicates the number of samples, input n means there are n accounts, n rows are entered, each line has name,endtime,costtime. A deduction of more than Endtime, the minimum number of points to be deducted.
Analysis: Compressed state, each state may be converted from a number of States, to find the least deduction, update the current status of the value.
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<queue>using namespacestd;structsubject{Charname[111]; intEnd, cost;} s[1<< -];structdp{intCost ; intreduced; intPre;} dp[1<< -];intvisit[1<< -];voidPrintintdate) { if(Date = =0) { return ; } intwhich; Which= date^Dp[date].pre; intNumber=0; while(which) {which>>=1; number++; } print (Dp[date].pre); printf ("%s\n", s[number-1]. Name);}intMain () {intT, N; scanf ("%d", &t); while(t--) {scanf ("%d", &N); for(intI=0; i<n; i++) {scanf ("%s%d%d", S[i]. Name, &s[i]. End, &S[i]. Cost); } intE = (1<<n)-1; dp[0].cost=0; dp[0].pre=-1; dp[0].reduced =0; visit[0] =1; memset (Visit,0,sizeof(visit)); for(intI=0; i<e; i++) { for(intj=0; j<n; J + +) { intDate1 =1<<J; if((i&date1) = =0)//This assignment has not been done {intDate2 = i|date1; Dp[date2].cost= Dp[i].cost +S[j]. cost; intreduce = dp[date2].cost-S[j]. End; if(reduce<0) Reduce=0; Reduce+=dp[i].reduced; if(Visit[date2])//Previous state existed {if(reduce<dp[date2].reduced) {dp[date2].reduced=reduce; Dp[date2].pre=i; } } Else{Visit[date2]=1; dp[date2].reduced=reduce; Dp[date2].pre=i; } }}} printf ("%d\n", dp[e].reduced); Print (e); } return 0;}
HDU 1074 Doing Homework