POJ 3211 Washing Clothes (平衡划分&01背包)
来源:互联网 发布:特种部队 知乎 编辑:程序博客网 时间:2024/05/16 18:23
http://poj.org/problem?id=3211
既然两个人可以同时洗同色的衣服,那么对每种颜色进行分析,转化为在sumtime/2的时间内能洗至多多久的衣服,则洗这种颜色的衣服至少用时sumtime-01pack(sumtime/2)
完整代码:
/*32ms,968KB*/#include<cstdio>#include<cstring>#include<map>#include<string>using namespace std;int cost[15][105], num[15], dp[100005];int _01pack(int V, int n, int kind){memset(dp, 0, sizeof(dp));int i, j;for (i = 0; i < n; i++)for (j = V; j >= cost[kind][i]; --j)dp[j] = max(dp[j], dp[j - cost[kind][i]] + cost[kind][i]);return dp[V];}int main(){int m, n, i, j, time, id, total_t, ans;char color[15];map<string, int> ma;while (scanf("%d%d", &m, &n), m){ma.clear();memset(num, 0, sizeof(num));memset(cost, 0, sizeof(cost));for (i = 0; i < m; ++i){scanf("%s", color);ma[color] = i;}for (i = 0; i < n; ++i){scanf("%d%s", &time, color);id = ma[color];cost[id][num[id]++] = time;}ans = 0;for (i = 0; i < m; ++i){total_t = 0;for (j = 0; j < num[i]; ++j)total_t += cost[i][j];ans += total_t - _01pack(total_t >> 1, num[i], i);}printf("%d\n", ans);}return 0;}
0 0
- 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背包
- POJ 3211Washing 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背包)
- Washing Clothes poj 3211(01背包)
- POJ 3211 Washing Clothes(01背包)@
- 01分组背包-poj 3211 Washing Clothes
- 组合数学:卡特兰数
- Ubuntu 13.04 安装搜狗输入法
- ANT编译JAVA源码
- ZOJ-3220
- 数据库锁机制
- POJ 3211 Washing Clothes (平衡划分&01背包)
- T.38软件模块中的消息数据流程
- SQL Server 2005 不能通过ip地址访问
- 项目三拓展
- hello
- poj(1185)状压DP
- [C_4]数组&字符串
- 给大家推荐一款数据库客户端软件——Navicat Premium
- 傅里叶变换