Washing Clothes
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

 
题解:

AC代码:
#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的更多相关文章

  1. POJ3211 Washing Clothes[DP 分解 01背包可行性]

    Washing Clothes Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9707   Accepted: 3114 ...

  2. poj3211 Washing Clothes

    Description Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a ...

  3. POJ3211(trie+01背包)

    Washing Clothes Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9384   Accepted: 2997 ...

  4. POJ3321Apple Tree[树转序列 BIT]

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26995   Accepted: 8007 Descr ...

  5. poj 01背包

    首先我是按这篇文章来确定题目的. poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<algo ...

  6. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

    题目链接: id=3211">poj3211  hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...

随机推荐

  1. ngTbale假分页实现排序、搜索、导出CSV等功能

    一. ngTable功能简化 使用ngTable经常有分页,排序,过滤等功能,实现诸多功能较为麻烦.为了方便开发过程,可以抽取一些table共同点写一个公有方法. 注意: 1. 由于很多特别的需求,可 ...

  2. 【原创】省市二级联动纯javascript

    // 北京 上海 天津 重庆 河北 山西 内蒙古 辽宁 吉林 黑龙江 江苏 浙江 安徽 福建 江西 山东 河南 湖北 湖南 广东 广西 海南 四川 贵州 云南 西藏 陕西 甘肃 宁夏 青海 新疆 香港 ...

  3. 凯尔卡C68全球版汽车电脑诊断仪

    产品简介: C68汽车故障诊断仪是凯尔卡公司新推出的一款集经济.简约.稳定.耐用于一体的汽车诊断设备, 该产品采用了最新的智能移植技术,集成度高:C68车型覆盖广,测试功能强大.数据准确等优点, 是目 ...

  4. IE6文字溢出BUG(多出来的猪问题)

    在IE6下使用浮动可能会出现文字重复的情况. 在IE6下,浮动层之间有注释文字的话,之前那个浮动层的内容文字就有可能遭遇一个“隐形”的复制,但是代码里查看文字可并没有多出来. 看个例子: HTML & ...

  5. windows7下实现局域网内文件共享

    1.右击桌面网络----属性----更改高级共享设置 (注释:查看当前网络 比如:家庭网络.公共网络 等!) "我这里为公共网络" 2.选择 公共网络---选择以下选项:启动网络发 ...

  6. hdu 5594 ZYB's Prime 最大流

    ZYB's Prime Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  7. TXT EXPLORER

    EXE程序:http://files.cnblogs.com/xe2011/RELEASE_TXTExplorer2014-08-25-165323.rar c# 源码:http://files.cn ...

  8. 40多个关于人脸检测/识别的API、库和软件

    英文原文:List of 40+ Face Detection / Recognition APIs, libraries, and software 译者:@吕抒真 译文:链接 自从谷歌眼镜被推出以 ...

  9. 乱谈Qt事件循环嵌套

    本文旨在说明:QDialog::exec().QMenu::exec()等开启的局部事件循环,易用的背后,还有很多的陷阱... 引子 Qt 是事件驱动的,基本上,每一个Qt程序我们都会通过QCoreA ...

  10. 如何在Linux下拷贝一个目录呢

    cp -af newadmin/movie/.   uploadfile/mallvideo/ 如何在Linux下拷贝一个目录呢?这好像是再简单不过的问题了. 比如要把/home/usera拷贝到/m ...