Test instructions: give you n (<=15) homework, each job has the latest submission time and need to do time, can only do one job at a time, each job beyond the latest submission time a day deduction points
Calculate the minimum score of the deduction and output the order of doing the job. If there are multiple minimum fractions, the output is based on the job dictionary order (note: input is also entered in dictionary order)
The first thing to think about is a violent DFS, but it will time out. Then we see that n is the maximum of only 15, so we can use the pressure DP, but the state cannot be represented by position
But we can do this: 0 means that this job has not been done, 1 means it has been used, and then traverse 0-> (1<<n)-1 greedy (for example: 3 (011) can find 2 (010) or 1 (001) to calculate), note the Save path and dictionary output
Note that we're going to use a pressure DP to find an event with only two states.
#include <Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<vector>#include<string>#include<cstdio>#include<cstring>#include<iomanip>#include<stdlib.h>#include<iostream>#include<algorithm>using namespacestd;#defineEPS 1E-8/*Note that there may be output -0.000*/#defineSGN (x) (X<-eps -1:x<eps? 0:1)//X is a comparison of two floating-point numbers, note the return integer#defineCvs (x) (x > 0.0 x+eps:x-eps)//floating point Conversion#defineZero (x) (((x) >0? ( x):-(x)) <eps)//determine if it equals 0#defineMul (A, B) (a<<b)#defineDir (A, B) (a>>b)typedefLong Longll;typedef unsignedLong Longull;Const intinf=1<< -;Constll inf=1ll<< -;Const DoublePi=acos (-1.0);Const intmod=1e9+7;Const intmax=2<< -;//compressed into now processed (1) and not processed (0)Const intMax2= Max;Charstr[ -][MAX2];intDeal[max2],val[max2],vis[max];intdp[2][max];//a record has a few days before a record minimum reduction scorevoidDP (intN) {dp[0][0]=dp[1][0]=0;//I didn't deal with it all.vis[0]=0; inttemp; for(intI=1;i< (1<<n); + +i) {dp[1][i]=Inf; Temp=i; for(intj=0; j<n;++j) {inttmp=1<<J; if((temp|tmp) ==temp)//first J of 1 { intminx=dp[1][i-tmp]+max (0, val[j]+dp[0][i-tmp]-Deal[j]); if(minx<=dp[1][i]) {dp[1][i]=Minx; dp[0][i]=dp[0][i-tmp]+Val[j]; Vis[i]=i-tmp; } } } } return;}intLowday (intm) { for(intI=0;; m>>=1,++i)if(!m)returnI-1;}voidDfsintNowintpre) { if(!Now ) {printf ("%s\n", Str[lowday (pre)]); return; } dfs (Vis[now],now); printf ("%s\n", Str[lowday (pre-Now )]); return;}intMain () {intT,n; scanf ("%d",&t); while(t--) {scanf ("%d",&N); for(intI=0; i<n;++i) {scanf ("%s%d%d",str[i],&deal[i],&Val[i]); } DP (n); printf ("%d\n", dp[1][(1<<n)-1]); DFS (vis[(1<<n)-1],(1<<n)-1); } return 0;}
HDU 1074 Doing Homework (pressure DP)