poj 3221 Washing Clothes(分组的0 1背包)
来源:互联网 发布:qq飞车刷点卷软件下载 编辑:程序博客网 时间:2024/04/30 00:02
题意: 两个人洗衣服, 每种颜色的衣服有多件, 要求两人只能同时洗相同颜色的衣服, 求洗衣服的最短时间;
这道题虽然简单, 但是是很好的一道题,需要多思考一步
分组的0 1背包
思路:因为只能同时洗相同颜色的衣服, 因此将不同颜色看为不同的组, 分别求出来每组的最短时间, 其和即为所求;每组最短时间其实就是0 1背包;
无语的是, 我在结构体中多加了一个够着函数, 结果一直超时……去掉后立即就AC了……
#include<iostream>#include<cstring> #include<cstdio> using namespace std;struct Node{char color[20];int num;int time[101];int sum;//无语, 我加上这个竟然超时!!!让我交了25+次, //不知道为啥? /*Node(){sum=0;num=0; } */ }node[15]; int main(){int m, n, time;char color[20]; int dp[100000]; while(scanf("%d%d", &m, &n) &&(m+n)){for(int i=0; i<m; i++){ scanf("%s", node[i].color);node[i].num=node[i].sum =0;} for(int i=0; i<n; i++){scanf("%d %s", &time, color); for(int j=0; j<m; j++){ if(strcmp(node[j].color, color) == 0) { int temp = node[j].num; node[j].time[temp] = time; node[j].sum += time; node[j].num++; break; } } }int ans = 0; for(int i=0; i<m; i++){ int sum = node[i].sum/2; memset(dp,0, sizeof(dp)); for(int j=0; j<node[i].num; j++) { for(int k=node[i].sum/2; k>=node[i].time[j];k--) { dp[k] = max(dp[k], dp[k-node[i].time[j]]+node[i].time[j]); } } ans += (node[i].sum-dp[sum]); } printf("%d\n", ans); } }
- poj 3221 Washing Clothes(分组的0 1背包)
- POJ 3211 Washing Clothes (分组背包+0/1背包)
- poj 3211 Washing Clothes(0/1背包)
- POJ 3211 Washing Clothes (0/1背包)
- POJ 3211 Washing Clothes 0-1背包
- poj 3211 Washing Clothes 0-1背包
- poj 3211 Washing Clothes【0-1背包】
- poj 3211 Washing Clothes(分组01背包)
- poj 3211 Washing Clothes 分组01背包
- 分组01背包 POJ Washing Clothes
- poj 3211 Washing Clothes 分组背包?
- 01分组背包-poj 3211 Washing Clothes
- poj 3211 Washing Clothes(分组01背包)
- POJ3211:Washing Clothes(分组01背包)
- POJ 3211Washing Clothes(01背包)
- POJ 3211 washing clothes (01背包)
- Washing Clothes poj 3211(01背包)
- POJ 3211 Washing Clothes(01背包)@
- 《Red5 用户参考手册》之八:Red5 核心技术第一章 在 Red5 里创建新应用
- Linux(CentOS 5.4 Linux) 服务器配置之DNS服务器配置应用
- 一道与预处理有关的题目
- 通用工具类-异步加载图片&缓存提取
- 何为高人——冷静与激情
- poj 3221 Washing Clothes(分组的0 1背包)
- 埃及粮食
- POJ 1106 Transmitters
- Andorid工具类-图片处理工具类
- c++中静态库和动态库的创建与链接(一)
- 2012 Multi-University Training Contest 1 Saving Princess claire(广搜)
- (莱昂氏unix源代码分析导读-35)缓存管理(上)
- 待学习的前端知识总结及相关资料 不定时更新
- JavaScrip学习之旅(2)引用外部JS文件