Big Event in HDU-01背包(dp思想)
来源:互联网 发布:淘宝代刷信誉平台 编辑:程序博客网 时间:2024/06/05 07:45
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171
问题描述:给出每个物体的价值和数量,如何分使得A,B所得价值最接近并且A的价值不能小于B
解决方法:dp[i]是体积为i时,获得的最大价值。易得: dp[j] = max(dp[j], dp[j - val[i]] + val[i]);
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int val[5000];int dp[250000];int main(){ int n, i, j, cnt, k, a, b, sum; while (cin >> n,n > 0) { cnt = 0; sum = 0; memset(dp, 0, sizeof(dp)); memset(val, 0, sizeof(val)); while (n--) { cin >> a >> b; while (b--) { val[cnt++] = a; sum += a; } } for (int i = 0; i < cnt; i++) for (int j = sum / 2; j >= val[i]; j--) dp[j] = max(dp[j], dp[j - val[i]] + val[i]); cout << sum - dp[sum / 2] << " " << dp[sum / 2] << endl; } return 0;}
0 0
- Big Event in HDU-01背包(dp思想)
- HDU 1171 Big Event in HDU (DP--01背包)
- (DP,背包,只有价值)Big Event in HDU -- HDOJ
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包问题)
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU (01背包)
- HDU 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU(01背包变形)
- HDU 1171 Big Event in HDU(01背包)
- hdu-1171 Big Event in HDU(01背包)
- HDU1171:Big Event in HDU(01背包)
- hdu1171 Big Event in HDU 01-背包
- hdu1171 Big Event in HDU 01背包
- Big Event in HDU (HDU_1171) 01背包
- hdu1171 Big Event in HDU --01背包
- Django之处理用户上传的文件
- Spring createBean过程中BeanPostProcessor的处理机会
- 【玩转SQLite系列】(五)SQLite数据库优化
- pat甲1011. World Cup Betting(水题)
- 指针
- Big Event in HDU-01背包(dp思想)
- Hibernate检索策略
- JDBC层次结构和基本构成
- 数据库(二)关系数据库
- Python计算机视觉:对图片进行格式转换
- 内存泄漏分析
- React Native android release 发布
- 基于ODPS的SQL语句
- Supervised Descent Method and its Applications to Face Alignment(SDM)