poj3211
| Time Limit: 1000MS | Memory Limit: 131072K | |
| Total Submissions: 9654 | Accepted: 3095 |
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
Source
| 时间限制:1000毫秒 | 内存限制:131072 k | |
| 总提交:9654年 | 接受:3095年 |
描述
Dearboy最近太忙了,现在他有一大堆衣服要洗。幸运的是,他有一个漂亮的和勤奋的女朋友去帮助他。品种的衣服颜色但每一块可以被看作是只有一种颜色。为了防止衣服染色在混合颜色,Dearboy和他的女友不得不洗完所有的衣服一个颜色之前的另一种颜色。
从经验Dearboy知道每件衣服需要多久一个人洗。每一块将被清洗Dearboy或女友但不是他们两人。这对夫妇可以同时洗两块。什么是他们所需要的最短的时间内完成这项工作吗?
输入
输入包含多个测试用例。每个测试用例开始于一条线的两个正整数M和N(M < 10 N < 100),衣服的颜色和数量。下一行包含字符串不超过10个字符,不含空格,这颜色的名称。然后描述衣服的N行。文件中的每一行包含的时间洗一些衣服(小于1000)和它的颜色。两个0跟随最后一个测试用例。
输出
为每个测试用例输出一个单独的行上这对夫妇需要清洗的时间。
样例输入
3 4
red blue yellow
2 red
3 blue
4 blue
6 red
0 0
样例输出
10
源
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct node{
int t;
char c[];
}col[];
char color[][];
int n,m,ans,sum[],f[];
int main(){
while(scanf("%d%d",&m,&n)==){
if(!n||!m) break;
memset(sum,,sizeof sum);
for(int i=;i<=m;i++) scanf("%s",color[i]);
for(int i=;i<=n;i++){
scanf("%d%s",&col[i].t,col[i].c);
for(int j=;j<=m;j++){
if(!strcmp(col[i].c,color[j])){
sum[j]+=col[i].t;break;//统计同一种颜色衣服的件数
}
}
}
ans=;
for(int i=;i<=m;i++){//求标记为i的颜色的时间
for(int j=;j<=sum[i]>>;j++) f[j]=;
for(int j=;j<=n;j++){
if(!strcmp(col[j].c,color[i])){
for(int v=sum[i]>>;v>=col[j].t;v--){
f[v]=max(f[v],f[v-col[j].t]+col[j].t);
}
} }
ans+=sum[i]-f[sum[i]>>];
}
printf("%d\n",ans);
}
return ;
}
poj3211的更多相关文章
- POJ3211 Washing Clothes[DP 分解 01背包可行性]
Washing Clothes Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9707 Accepted: 3114 ...
- poj3211 Washing Clothes
Description Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a ...
- POJ3211(trie+01背包)
Washing Clothes Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9384 Accepted: 2997 ...
- POJ3321Apple Tree[树转序列 BIT]
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26995 Accepted: 8007 Descr ...
- poj 01背包
首先我是按这篇文章来确定题目的. poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<algo ...
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
题目链接: id=3211">poj3211 hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...
随机推荐
- Junit 测试断言说明
Assert.assertEquals("发生错误时报告消息","预期值","生产值"); Assert.assertEquals(&quo ...
- HTTP(一) 连接管理
・HTTP是如何使用TCP连接的 HTTP传送一条报文时,以流的形式将报文数据内容通过一条打开的TCP连接按序传输. TCP收到数据流之后,由TCP/IP软件将数据流砍成被称作段的小数据块,并将段封装 ...
- (4)html表格
本节解说 :html的表格 表格: *<table></table> 标签定义 HTML 表格. *简单的 HTML 表格由 table 元素以及一个或多个 tr.th 或 t ...
- eclipse下安装Extjs的插件spket
最近项目要用ext进行开发,所以这段时间开始学习ext. 我这里用的是ext3.0,eclipse3.5. 每次都要去查API,很烦,所以装个EXT提示的插件对初学者来说有很大的帮助. 假设你已经下载 ...
- Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- cocos2dx 屏幕适配策略
cocos2dx的常用函数: CCEGLView::sharedOpenGLView()->setDesignResolutionSize() //设计分辨率大小(即开发时为基准的屏幕分辨率) ...
- DCEF3 相关资料
DCEF3 调用 js http://www.cnblogs.com/Delphi-Farmer/p/4103708.html interface uses ceflib;//其它 type //这里 ...
- 【机试题】c# 是否是素数,找出比它大的第一个素数
题目: 输入一个自然数 判断是否是素数,是素数则提示是素数,否则找出比它大的第一个素数 代码: Console.WriteLine("请输入任意一个自然数."); string n ...
- PhoneGap+jQuery Mobile+Rest 访问远程数据
最近研究Mobile Web技术.发现了一个好东西-PhoneGap! 发现用PhoneGap+jQuery Mobile是一个很完美的组合! 本实例通俗易懂.适合广大开发人群:高富帅.白富美.矮穷戳 ...
- rqnoj-217-拦截导弹-最长不上升子序列以及不上升子序列的个数
最长上升子序列的O(n*log(n))算法. 不上升子序列的个数等于最长上升子序列的长度. #include<string.h> #include<stdio.h> #incl ...