POJ 3211 Washing Clothes
Washing Clothes
Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 10738 Accepted: 3480 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
POJ Monthly–2007.04.01, dearboy
题意男女朋友洗衣服,可以同时洗一种颜色的衣服,求最短时间。 对于每种颜色的衣服,就是容量为洗衣服时间总和一半的01背包问题。 代码
#include<iostream>
#include <cstdio>
#include<algorithm>
#include <cstring>
#include <map>
#include<vector>
using namespace std;
int dp[1000005];
int main(){
int m,n;
while(cin>>m>>n&&(m||n)){
vector <int >x[11];
map<string,int>q;
string a;int b;
int sum[11]={0};
for(int i=0;i<m;i++)
{
cin>>a;
q[a]=i;}
for(int i=0;i<n;i++)
{ cin>>b>>a;
x[q[a]].push_back(b);
sum[q[a]]+=b;
}
int tot=0;
for(int i=0;i<m;i++)
{
memset(dp,0,sizeof(dp));
for(int j=0;j<x[i].size();j++)
for(int k=sum[i]/2;k>=x[i][j];k--)
dp[k]=max(dp[k],dp[k-x[i][j]]+x[i][j]);
tot+=(sum[i]-dp[sum[i]/2]);
}
cout<<tot<<endl;
}
return 0;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- R语言区间数据回归分析
- R语言ggsurvplot绘制生存曲线报错 : object of type ‘symbol‘ is not subsettable
- R软件SIR模型网络结构扩散过程模拟
- R语言中使用线性模型、回归决策树自动组合特征因子水平
- R语言缺失值的处理:线性回归模型插补
- R语言如何解决线性混合模型中畸形拟合(Singular fit)的问题
- Android如何在Gradle中更改APK文件名详解
- 面试中常见的 C 语言与 C++ 区别的问题
- Linux系统实现ansible自动化安装配置httpd的方法
- 常用Linux发行版镜像源配置小结
- Linux如何处理文件已删除但空间不释放的问题
- 解析linux或android添加文件系统的属性接口的方法
- linux查看软件的安装位置简单方法
- 使用 bind 设置 DNS 服务器的方法
- Linux jdk安装及环境变量配置教程(jdk-8u144-linux-x64.tar.gz)