POJ 3211 Washing Clothes(01背包/可行性判断)
来源:互联网 发布:用友软件记账流程 编辑:程序博客网 时间:2024/06/07 10:03
题目链接:
POJ 3211 Washing Clothes
题意:
n堆衣服和m种颜色,每堆衣服的颜色都相同,给出每堆衣服的颜色和洗这堆衣服的时间,有两个人同时洗衣服,但是必须洗完一种颜色的衣服之后才能洗下一种颜色的衣服。问洗完这些衣服的最短时间是多少?
分析:
考虑洗完每种颜色的衣服的最短时间。
假设洗完一种颜色衣服总共需要sum的时间,由于是两个人同时洗,考虑最少时间,那么就相当于将sum尽可能分为最接近的两个数。并且这两个数都是可以由这种颜色的所有堆衣服数量组成的。也就是用这种颜色的所有堆衣服数量最大能组成不超过sum/2的数是多少?假设其为tmp,则在这种颜色的衣服上耗费的时间为sum-t.
求t的过程就是01背包的可行性判断。
//432K 16MS#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAX_SUM=10100;int m,n;char name[15][15];int num[15],sum[15],data[15][110],dp[MAX_SUM];int main(){ while(~scanf("%d%d",&m,&n)&&(n||m)){ for(int i=1;i<=m;i++){ scanf("%s",name[i]); } memset(num,0,sizeof(num)); memset(sum,0,sizeof(sum)); for(int i=1;i<=n;i++){ char tmp[15]; int t; scanf("%d%s",&t,tmp); for(int j=1;j<=m;j++){ if(strcmp(tmp,name[j])==0){ data[j][num[j]]=t; sum[j]+=t; num[j]++; break; } } } int ans=0; for(int i=1;i<=m;i++){ memset(dp,0,sizeof(dp)); dp[0]=1;//dp[i]=1表示可以组成i for(int j=0;j<num[i];j++){ for(int k=sum[i]/2;k>=1;k--){ if(dp[k]==0&&dp[k-data[i][j]]==1) dp[k]=1; } } for(int j=sum[i]/2;j>=0;j--){ if(dp[j]){ //printf("i=%d j=%d sum[i]-j=%d\n",i,j,sum[i]-j); ans+=sum[i]-j; break; } } } printf("%d\n",ans); } return 0;}
0 0
- POJ 3211 Washing Clothes(01背包/可行性判断)
- POJ 3211Washing Clothes(01背包)
- POJ 3211 washing clothes (01背包)
- Washing Clothes poj 3211(01背包)
- POJ 3211 Washing Clothes(01背包)@
- poj 3211 Washing Clothes(01背包)
- POJ 3211 Washing Clothes【01背包】
- poj 3211 Washing Clothes(01背包问题)
- POJ 3211 Washing Clothes【01背包+STL】
- poj 3211 Washing Clothes(01背包)
- poj 3211 Washing Clothes 01背包
- poj 3211 Washing Clothes 01背包
- poj 3211 Washing Clothes 01背包问题
- poj 3211 Washing Clothes 分组01背包
- Washing Clothes - POJ 3211 01背包
- POJ 3211 Washing Clothes(01背包)
- POJ 3211 - Washing Clothes(01背包)
- poj 3211 Washing Clothes 01背包
- c++ iostream库的一些讨论
- 辛星浅析array_walk()和array_map()的联系和区别
- 给定两个有序数组,找出合并之后的数组中位数
- C# WPF 按钮模板
- JDBC的学习总结
- POJ 3211 Washing Clothes(01背包/可行性判断)
- 带模板参数的运算符重载
- 在阿里云中编译Linux4.5.0内核 - Ubuntu内核编译教程
- LeetCode 107 Binary Tree Level Order Traversal II
- 译:Google的大规模集群管理工具Borg(一)------ 用户视角的Borg特性
- 用启动U盘安装ubuntu14.04
- 309. Best Time to Buy and Sell Stock with Cooldown
- 232. Implement Queue using Stacks
- java程序控制台编译成功但无法运行,报“找不到或无法加载主类”错误!