General test Instructions: There are n pieces of clothing, M color, someone and his female cannon washing clothes, must be a color wash, to wash another color, each dress has time, the person washes all the same, ask for the least.
POJ the evil C + + and g++, I have been ce three times
/*Backpack Ah ... There are so many play do not know is not by the tree-shaped DP dizzy, one up on the set up a three-dimensional array, "f[i][j][0" on behalf of the former I clothes, time difference is J, and the boys wash much of it. After two hours to find the wrong idea, this will make two backpacks no difference, the answer must be wrong. Positive solution: For each color, do a 01 knapsack tree, add j this volume can fill out, then another backpack volume is sum-j, then Ans=min (Ans,max (j,sum-j))*/#include<cstdio>#include<iostream>#include<cstring>#include<map>#include<vector>#defineN 110#defineM 100010#defineINF 10000010using namespacestd;intF[m],num[n],sum[n],w[n][n],n,m;map<string,int>color;voidinit () { for(intI=1; i<=n;i++) { strings; CIN>>s; Color[s]=i; } for(intI=1; i<=m;i++) { intTstrings; scanf ("%d", &t);cin>>s; intC=Color[s]; NUM[C]++; W[C][NUM[C]]=T; SUM[C]+=T; } inttot=0; for(intt=1; t<=n; t++) { if(!num[t])Continue; Memset (F,0,sizeof(f)); intans=INF; f[0]=1; for(intI=1; i<=num[t];i++) for(intj=sum[t];j>=w[t][i];j--) F[j]+=f[j-W[t][i]]; for(intI=0; i<=sum[t];i++) if(F[i]) ans=min (Max (i,sum[t]-i), ans); Tot+=ans; } printf ("%d\n", tot);}intMain () { while(~SCANF ("%d%d",&n,&m) {memset (num,0,sizeof(num)); memset (SUM,0,sizeof(sum)); Memset (W,0,sizeof(w)); Memset (F,0,sizeof(f)); if(n==0&&m==0) Break; Init (); } return 0;}
View Code
Washing Clothes (POJ 3211)