标签:des style http color java os io strong
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 8637 | Accepted: 2718 |
Description
Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a beautiful and hard-working girlfriend to help him. The clothes are in varieties of colors but each piece of them can be seen as of only one color. In order to prevent the clothes from getting dyed in mixed colors, Dearboy and his girlfriend have to finish washing all clothes of one color before going on to those of another color.
From experience Dearboy knows how long each piece of clothes takes one person to wash. Each piece will be washed by either Dearboy or his girlfriend but not both of them. The couple can wash two pieces simultaneously. What is the shortest possible time they need to finish the job?
Input
The input contains several test cases. Each test case begins with a line of two positive integers M and N (M < 10, N < 100), which are the numbers of colors and of clothes. The next line contains Mstrings which are not longer than 10 characters and do not contain spaces, which the names of the colors. Then follow N lines describing the clothes. Each of these lines contains the time to wash some piece of the clothes (less than 1,000) and its color. Two zeroes follow the last test case.
Output
For each test case output on a separate line the time the couple needs for washing.
Sample Input
3 4 red blue yellow 2 red 3 blue 4 blue 6 red 0 0
Sample Output
10
Source
#include<cstdio> #include<map> #include<iostream> #include<cstring> using namespace std; const int maxn=100000+10; int dp[maxn]; struct clothes { int num;//颜色相同的衣服的编号 int sum;//颜色形同的衣服的总数 char color[100];//颜色 int time[105];//颜色相同的不同衣服的时间 }clo[10+10]; int main() { int m,n,u,max_pack,ans; char str[100+10]; while(~scanf("%d%d",&m,&n)) { if(n==0&&m==0) return 0; for(int i=1;i<=m;i++) { scanf("%s",clo[i].color); clo[i].num=1; clo[i].sum=0; } for(int i=1;i<=n;i++) { scanf("%d%s",&u,str); for(int j=1;j<=m;j++) { if(strcmp(str,clo[j].color)==0) { int tmp=clo[j].num; clo[j].time[tmp]=u; clo[j].sum=clo[j].sum+u; clo[j].num++; } } } for(int i=1;i<=m;i++) clo[i].num--; ans=0; for(int i=1;i<=m;i++) { memset(dp,0,sizeof(dp)); max_pack=clo[i].sum/2; for(int j=1;j<=clo[i].num;j++) for(int k=max_pack;k>=clo[i].time[j];k--) dp[k]=max(dp[k],dp[k-clo[i].time[j]]+clo[i].time[j]); ans=ans+max(dp[max_pack],clo[i].sum-dp[max_pack]); } cout<<ans<<endl; } return 0; }
2 10 1 20 1 3 10 1 20 2 30 1 -1
20 10 40 40
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn=250000+10; int dp[maxn]; int sum[50+10],val[50+10]; int kind[5000+10]; int main() { int n,max_pack,ans,cal,Max; while(~scanf("%d",&n)) { memset(dp,0,sizeof(dp)); if(n<=0) return 0; cal=1; max_pack=0; for(int i=1;i<=n;i++) { scanf("%d%d",&val[i],&sum[i]); max_pack+=sum[i]*val[i]; for(int j=1;j<=sum[i];j++) { kind[cal]=val[i]; cal++; } } cal--; Max=max_pack/2; for(int i=1;i<=cal;i++) for(int j=Max;j>=kind[i];j--) dp[j]=max(dp[j],dp[j-kind[i]]+kind[i]); ans=max(dp[Max],max_pack-dp[Max]); cout<<ans<<" "<<max_pack-ans<<endl; } return 0; }
poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包),布布扣,bubuko.com
poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
标签:des style http color java os io strong
原文地址:http://blog.csdn.net/u014303647/article/details/38470339