均分背包 HDU1171

 1 #include <cstring>
 2 #include <iostream>
 3 #include <algorithm>
 4
 5 using namespace std;
 6
 7 long long dp[250010];
 8 int v[5500][2];
 9
10 int main()
11 {
12     int n;
13     while(cin>>n&&n>0)
14     {
15         long long int sum=0;
16         long long int req;
17         memset(v,0,sizeof(v));
18         for(int i=0;i<n;i++)
19         {
20             cin>>v[i][0]>>v[i][1];
21             sum+=v[i][0]*v[i][1];
22         }
23         req=sum/2;
24         memset(dp,0,sizeof(dp));
25         for(int i=0;i<n;i++)
26         {
27             for(int t=0;t<v[i][1];t++)
28             for(int vv=req;vv>=v[i][0];vv--)
29             {
30                 dp[vv]=max(dp[vv-v[i][0]]+v[i][0],dp[vv]);
31             }
32         }
33         cout<<sum-dp[req]<<" "<<dp[req]<<endl;
34     }
35     return 0;
36 }

时间: 2024-10-21 05:52:08

均分背包 HDU1171的相关文章

HDU1171(01背包均分问题)

Big Event in HDU Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been spli

HDU-1171 Big Event in HDU (多重背包)

Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big

hdu2110(多重背包)

http://acm.hdu.edu.cn/showproblem.php?pid=2110 就是个多重背包,有坑点-.-.注意答案模10000中间结果有可能会爆所以计算时就要取模: 由于必须能均分三份所以总价值肯定能除尽3,只要计算出1/3总价值的方案数即可,也就是2/3总价值的方案数: #include<iostream>#include<cstring>#include<cstdio>using namespace std;#define inf 0x3f3f3f

#1038 : 01背包

#1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了! 小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖品需要need(i)张奖券进行兑换,同时也只能兑换一次,为了使得辛苦得到的奖券不白白浪费,小Ho给每件奖品都评了分,其中第i件奖品的评分值为value(i),表示他对这件奖品的喜好值.现在他想知道,凭借他手上的这

hdoj 1059 Dividing 【多重背包】||【优化母函数】

题意:每一种弹珠(marble)的都有各自的价值,第一种为1, 第二种为2,..,给出你每种弹珠的数量,求能不能将价值总和均分. 策略:rt: 这道题比赛的时候没有想到用母函数,就用了多重背包来解,之后递交的时候时间居然超600ms,我再一看递交排行都是0ms(⊙﹏⊙b汗).看到讨论区有人说母函数也可以,于是就写了个普通的,可惜TL了.果然还是需要优化啊...于是游来游去果然0ms(O(∩_∩)O哈哈哈~). 说一下0秒的思路,因为只是问能不能均分,所以我们没有必要找种类数,找到了就定义为1好了

poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

题目链接: poj3211  hdu1171 这个题目比1711难处理的是字符串如何处理,所以我们要想办法,自然而然就要想到用结构体存储,所以最后将所有的衣服分组,然后将每组时间减半,看最多能装多少,最后求最大值,那么就很愉快的转化成了一个01背包问题了.... hdu1711是说两个得到的价值要尽可能的相等,所以还是把所有的价值分为两半,最后01背包,那么这个问题就得到了解决.. 题目: Washing Clothes Time Limit: 1000MS   Memory Limit: 13

POJ 1014 Dividing(多重背包)

Dividing Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could

hdu1171 Big Event in HDU 01-背包

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever bee

【背包专题】G - Dividing hdu 1059【多重背包】

Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the colle