POJ3211Washing Clothes
来源:互联网 发布:软件开发前端和后端 编辑:程序博客网 时间:2024/05/22 13:17
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 M strings 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 4red blue yellow2 red3 blue4 blue6 red0 0
Sample Output
10
Source
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n,m;char col[11][11];int cnt[11],cost[11][111];int sum[11],dp[50000];int getid(char s[]){ int i; for(i=0; i<m; i++) if(strcmp(col[i],s)==0) return i;}int main(){ int i,j,k,tcost,id; char str[11]; while(cin>>m>>n) { if(n==0&&m==0) break; memset(sum,0,sizeof(sum)); memset(cnt,0,sizeof(cnt)); for(i=0; i<m; i++) cin>>col[i]; for(i=0; i<n; i++) { cin>>tcost>>str; id=getid(str); cost[id][cnt[id]++]=tcost; sum[id]+=tcost; } int ans=0; for(i=0; i<m; i++) { memset(dp,0,sizeof(dp)); int mid=sum[i]/2; for(j=0; j<cnt[i]; j++) for(k=mid; k>=cost[i][j]; k--) dp[k]=max(dp[k],dp[k-cost[i][j]]+cost[i][j]); ans+=(sum[i]-dp[mid]); } cout<<ans<<endl; } return 0;}
- POJ3211Washing Clothes
- POJ3211Washing Clothes题解动态规划DP
- POJ3211Washing Clothes(分组01背包)
- poj3211Washing Clothes(分成多组01背包) .......经典
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
- clothes
- Clothes
- Clothes Phrase
- no one wears clothes
- POJ 3211 Washing Clothes
- POJ 3211 Washing Clothes
- Poj 3211 Washing Clothes
- POJ 3211 Washing Clothes
- POJ3211 Washing Clothes
- poj 3211 Washing Clothes
- English expressions about clothes
- poj3211 Washing Clothes
- POJ 3211 Washing Clothes
- Delphi控制编辑类控件不能粘贴
- js笔记
- Windows8与VMWare不兼容的解决方案
- 批处理之FOR语句祥解
- JAVA JSON 数据 大全
- POJ3211Washing Clothes
- 重装SQL Server 2005的一般方法:
- js获取对象位置的方法
- 今日关于HTML/CSS回顾
- 十年优秀网络玄幻小说大点评(推荐)
- 创建兼容 IE/FireFox 的 event 及 event 的 srcElement、fromElement、toElement 属性
- 高通内部文件泄密 Android 5.0 发布时间曝光
- 为应用指定多个配置文件
- ABAP BDC录屏及遇到的问题