POJ 3211 Washing Clothes
来源:互联网 发布:数值仿真软件 编辑:程序博客网 时间:2024/06/12 16:18
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 4
red blue yellow
2 red
3 blue
4 blue
6 red
0 0
Sample Output
10
思路
大意是这个男孩和他女盆友一起洗衣服,不过不同颜色的衣服不能一起洗,
也就是说他和他女盆友只可以一起洗同种颜色的衣服,给你颜色数,和多少衣服,问最少可有用多长时间洗完。
第一眼,这个题太麻烦,第二眼,怎么像01背包?第三眼,还真是用01背包做
统计衣服的颜色种数,每种颜色跑01背包,求和。
**#include<cstdio>#include<iostream>#include<cstdlib>#include<cstring> #define M 500010using namespace std;struct node{ int sum;//洗这种颜色衣服所用总时间 int num;//这种颜色衣服的件数 char color[20];//衣服的颜色 int ti[110];//每件衣服洗用的时间 } t[11];int f[M];int n,m;int hh(){ system("color 3e"); int time; char col[20]; while(~scanf("%d%d",&m,&n)&&(n+m)) { for(int i=1;i<=10;i++) { t[i].num=0; t[i].sum=0; } for(int i=1;i<=m;i++) scanf("%s",t[i].color); for(int i=1;i<=n;i++) { scanf("%d%s",&time,col); for(int j=1;j<=m;j++) { if(!strcmp(col,t[j].color)){ //WA了千百遍,只因这的j写成了i (T_T) t[j].num++; t[j].ti[t[j].num]=time; t[j].sum+=time; } } } int ans=0; for(int i=1;i<=m;i++) { memset(f,0,sizeof(f)); int sum1=t[i].sum/2; for(int j=1;j<=t[i].num;j++) for(int k=sum1;k>=t[i].ti[j];k--) f[k]=max(f[k],f[k-t[i].ti[j]]+t[i].ti[j]); ans+=t[i].sum-f[sum1]; } printf("%d\n",ans); } return 0;}int hhh=hh();int main(){;}**
- POJ 3211 Washing Clothes
- POJ 3211 Washing Clothes
- Poj 3211 Washing Clothes
- POJ 3211 Washing Clothes
- poj 3211 Washing Clothes
- POJ 3211 Washing Clothes
- POJ 3211Washing Clothes
- poj 3211 Washing Clothes
- POJ 3211 Washing Clothes
- POJ-3211 Washing Clothes
- POJ 3211 Washing Clothes
- POJ 3211 Washing Clothes(???)
- poj 3211 Washing Clothes
- poj 3211 Washing Clothes(背包)
- POJ 3211 Washing Clothes 可能会
- POJ 3211 Washing Clothes【01背包】
- poj 3211 Washing Clothes(01背包问题)
- POJ 3211 Washing Clothes【01背包+STL】
- IntelliJ IDEA Properties 文件代码不高亮 解决方案
- 理解MySQL——索引与优化
- ubuntu软件安装:qq+mysql+Chrome+unity tweak tool+subline text3+inkScape+Unetbootin+Gimp+Vmware pro 12
- 浅谈STL之(一) 排序函数——next_permutation(a,a+n)
- JAVA计算日期时间差
- POJ 3211 Washing Clothes
- android apk批量打包工具
- hdu 5783 Divide the Sequence【水题】
- JAVA日期类型
- Android录制视频,仿微信小视频录制(一)
- requestWindowFeature(Window.FEATURE_NO_TITLE)无效解决方法
- 【Android】SlidingMenu属性详解
- python 实现tif图片转jpg图片 windows下
- [Arduino]HC-06蓝牙模块使用小结