通过分析,要使A>=B并且差值最小。所以只要使sum/2的容量下,B最大就Ok了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
#define N 5000000
int dp[N];
struct Node{
int v,m;
}num[];
bool cmp(Node a,Node b){
return a.v<b.v;
}
int main(void)
{
int n;
int i,j,k;
while(cin>>n&&n>){
int sum=;
for(i=;i<=n;i++){
cin>>num[i].v>>num[i].m;
sum+=num[i].v*num[i].m;
}
sort(num+,num++n,cmp);
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
for(j=;j<=num[i].m;j++)
for(k=sum/;k>=num[i].v;k--){
dp[k]=max(dp[k],dp[k-num[i].v]+num[i].v);
}
cout<<sum-dp[sum/]<<" "<<dp[sum/]<<endl; }
return ;
}

HDU1171:Big Event in HDU(多重背包分析)的更多相关文章

  1. hdu1171 Big Event in HDU(多重背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 多重背包题目不难,但是有些点不能漏或错. #include<iostream> #includ ...

  2. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  3. HDU 1171 Big Event in HDU (多重背包变形)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU - 1171 Big Event in HDU 多重背包

    B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. B ...

  5. HDU-1171 Big Event in HDU(生成函数/背包dp)

    题意 给出物品种类,物品单价,每种物品的数量,尽可能把其分成价值相等的两部分. 思路 背包的思路显然是用一半总价值当作背包容量. 生成函数则是构造形如$1+x^{w[i]}+x^{2*w[i]}+.. ...

  6. hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

  8. HUD 1171 Big Event in HDU(01背包)

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  9. HDU 1171 Big Event in HDU dp背包

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...

随机推荐

  1. http://webhelp.esri.com/arcgisexplorer/2500/zh-CN/index.html#add_raster_data.htm

    http://webhelp.esri.com/arcgisexplorer/2500/zh-CN/index.html#add_raster_data.htm

  2. 在Centos 5.x或6.x上安装RHEL EPEL Repo

    本文介绍了如何在CentOS 5.x或者CentOS 6.x的系统上使用Fedora Epel repos一个第三方repo:remi资源库.这些资源包并不是天然地支持CentOS,但是提供了很多流行 ...

  3. rsyslog 配置

    在Debian环境下: 1,配置文件在/etc/rsyslogd.conf下: 2,如果要增加配置,并且不想直接修改rsyslogd.conf文件,可以在/etc/rsyslog.d/目录下增加文件, ...

  4. OA项目之打印

    打印 若此页有一个打印按钮: <input type="button" id="btnPrint" class="button_sm7" ...

  5. Problem 2128 最长子串(kmp+strstr好题经典)

     Problem 2128 最长子串 Accept: 134    Submit: 523Time Limit: 3000 mSec    Memory Limit : 65536 KB  Probl ...

  6. 利用aspose.cell把数据导出到excel

    /// <summary> /// 导出数据到本地 /// </summary> /// <param name="dt">要导出的数据< ...

  7. if和switch

    在 JavaScript 中,我们可使用以下条件语句:if 语句 -                        只有当指定条件为 true 时,使用该语句来执行代码if...else 语句 -   ...

  8. malloc 申请得到的内存后,再 free 释放它的时候,操作系统会立即收回那块内存吗?

    stackoverflow上的回答: In many malloc/free implementations, free does normally not return the memory to  ...

  9. STL模板_multimap_智能指针作为键值

    map的键值的类型 -可以是自定的类型(对象.函数指针.智能指针....) -但是有副作用-当自己定义的类型键值无法用系统自己提供的 < 或者 > 进行排序的时候,会出现各种问题 -所以需 ...

  10. shell 守护进程

    #!/bin/sh #守护进程,接受2个参数 #para CMD 执行的命令 #pare ID 唯一标识改命令 if [ "$1" = "" -o " ...