01背包问题(两种状态)UVa-12563
来源:互联网 发布:淘宝双十一红包群 编辑:程序博客网 时间:2024/06/06 16:30
原题 https://vjudge.net/problem/UVA-12563
对于每移动一步都有两种状态,创建了两个数组来维护状态进行状态转移,也可用一个结构体,这两种状态为结构体的成员函数类似于http://blog.csdn.net/u013480600/article/details/40376143的思路
#include <iostream>#include <cstring>#include <algorithm>using namespace std;int time_[5555] = {0};int dp[255555] = {0};int main(){ int n; while (cin >> n && n != -1) { memset(time_, 0, sizeof(time_)); memset(dp, 0, sizeof(dp)); int index = 0; int len = 0; while (n--) { int v, c; cin >> v >> c; len += v * c; { time_[index++] = v; } while (c--) } for (int i = 0; i < index; i++) { for (int j = len / 2; j >= time_[i]; j--) // for (int j = 0; j <= len / 2; j++) { dp[j] = max(dp[j], dp[j - time_[i]] + time_[i]); } } cout << len - dp[len / 2] << " " << dp[len / 2] << endl; } return 0;}
阅读全文
0 0
- 01背包问题(两种状态)UVa-12563
- 01背包的两种初始化问题
- uva 12563(01背包)
- UVA 12563 01背包
- UVA-12563 01背包
- 01背包类型问题的两种解法
- Uva 562 Dividing coins(01背包问题)
- 【UVA】624-CD(动态规划01背包问题)
- UVA - 10465 Homer Simpson 01背包问题(无限)
- UVA 10817 Headmaster's Headache(dp 状态压缩 01背包)
- uva 624 CD 01背包状态压缩记路径
- POJ 状态DP+ 01 背包问题
- 动态规划-背包问题(状态转换)
- UVA - 624 CD 01背包问题
- UVA - 10130 SuperSale 01背包问题
- UVA 624CD(01背包问题)
- UVA 562Dividing coins(01 背包问题)
- 两类背包问题
- 蟹黄杯champion == hyhmnn's blog record begins !!!
- 【java学习】java三大器
- 1148: 考试排名
- macOS 10.12 + Anaconda + Matlab 2016b + Caffe(CPU mode)
- CodeForces
- 01背包问题(两种状态)UVa-12563
- KMA算法实现
- 插入排序代码
- 听张方方学长分享经验有感
- 模态框modal
- Linux 中shell学习
- 数据探索和预处理可能涉及到的算法
- List在执行remove方法不能删除指定的对象
- 【设计模式】—— 职责链模式ChainOfResponsibility