HDU 1171 —— Big Event in HDU 01背包入门
来源:互联网 发布:js json数组 添加 编辑:程序博客网 时间:2024/05/29 18:16
http://acm.hdu.edu.cn/showproblem.php?pid=1171
题意:有n种数,下面n行给出每种数的大小以及个数,将所有的数字分成两堆,且两堆的差值尽可能的小;
注意点:1、容量是sum/2;2、n<0 break,而不是-1;3、数组大小不要开错;
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn = 250000+5;int dp[maxn];int a[maxn];int n;int main(){while(~scanf("%d", &n)){if(n < 0)break;memset(dp, 0, sizeof dp);int cnt = 0;int sum = 0;for(int i = 1;i<=n;i++){int x, y;scanf("%d%d", &x, &y);sum += (x*y);while(y--){a[++cnt] = x;}}for(int i = 1;i<=cnt;i++){for(int j = sum/2;j>=a[i];j--){dp[j] = max(dp[j], dp[j-a[i]]+a[i]);}}printf("%d %d\n", max(sum-dp[sum/2], dp[sum/2]), min(sum-dp[sum/2], dp[sum/2]));}return 0;}
0 0
- HDU 1171 —— Big Event in HDU 01背包入门
- hdu 1171 Big Event in HDU(01背包&多重背包)
- [HDU 1171 Big Event in HDU]背包
- hdu 1171 Big Event in HDU 01背包
- HDU--航但--1171--Big Event in HDU--01背包
- Big Event in HDU - HDU 1171 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背包)
- HDU 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU(01背包变形)
- 第十六周项目1—交换排序之冒泡排序
- 第十六周 项目1 验证算法 基数排序
- Leetcode194: Range Sum Query 2D - Immutable
- Java基础编程之统计字符个数
- 在 Spring 3.1 中使用 @Cacheable 实现缓存
- HDU 1171 —— Big Event in HDU 01背包入门
- tomcat配置文件server.xml详解
- 第14周项目4(6)最短路径
- MySQL数据库中的大小写敏感性
- Android开源项目第一篇——个性化控件(View)篇
- 第16周项目2——大数据集上排序算法性能的体验
- 第十六周--项目三--归并排序算法的改进
- 16周—项目(一)—归并排序,基数排序
- android连接wifi代码