背包模版:

Big Event in HDU

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

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 event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
Sample Input
2 10 1 20 1 3 10 1 20 2 30 1 -1
Sample Output
20 10 40 40
Author
lcy
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4
 5 using namespace std;
 6
 7 int v;
 8 int dp[333333];
 9
10 void zpack(int *a,int c,int w)
11 {
12     for(int i=v;i>=c;i--)
13         a[i]=max(a[i],a[i-c]+w);
14 }
15
16 void cpack(int *a,int c,int w)
17 {
18     for(int i=c;i<=v;i++)
19         a[i]=max(a[i],a[i-c]+w);
20 }
21
22 void multipack(int *a,int c,int w,int m)
23 {
24     if(c*m>=v)
25     {
26         cpack(a,c,w);
27         return ;
28     }
29
30     int k=1;
31     while(k<m)
32     {
33         zpack(a,k*c,k*w);
34         m-=k;
35         k*=2;
36     }
37
38     zpack(a,m*c,m*w);
39 }
40
41 int c[100];
42 int m[100];
43
44 int main()
45 {
46     int n;
47 while(scanf("%d",&n)&&n>0)
48 {
49     memset(c,0,sizeof(c));
50     memset(m,0,sizeof(m));
51     memset(dp,0,sizeof(dp));
52
53     int sum=0;
54     for(int i=0;i<n;i++)
55     {
56         scanf("%d%d",&c[i],&m[i]);
57         sum+=c[i]*m[i];
58     }
59     v=sum/2;
60     for(int i=0;i<n;i++)
61         multipack(dp,c[i],c[i],m[i]);
62
63     printf("%d %d\n",sum-dp[v],dp[v]);
64
65 }
66
67     return 0;
68 }

转载于:https://www.cnblogs.com/CKboss/archive/2013/05/27/3102820.html

HDOJ 1171 Big Event in HDU相关推荐

  1. DP Big Event in HDU

    Big Event in HDU Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) T ...

  2. Big Event in HDU

    提供多重背包的一些思路 Description Nowadays, we all know that Computer College is the biggest department in HDU ...

  3. HDU1171-Big Event in HDU

    描述: Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don ...

  4. 动态规划题目——背包

    背包问题 1. 01背包 [HDOJ 2955.Robberies] [HDOJ 1203.I NEED A OFFER!] [HDOJ 1864.最大报销额] 2. 完全背包 [HDOJ 2159. ...

  5. 杭电OJ分类题目(1)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...

  6. 两条直线的交点 c语言,计算两条直线的交点(C#)

    PS:从其他地方看到的源码是有问题的.下面是修正后的 /// /// 计算两条直线的交点 /// /// L1的点1坐标 /// L1的点2坐标 /// L2的点1坐标 /// L2的点2坐标 /// ...

  7. 动态规划总结与题目分类

    源博客链接:http://blog.csdn.net/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少 ...

  8. dp进阶之FFT加速+数据结构优化+不等式优化

    快速傅里叶变换 快速傅里叶变换(英语:Fast Fourier Transform, FFT),是快速计算序列的离散傅里叶变换(DFT)或其逆变换的方法.傅里叶分析将信号从原始域(通常是时间或空间)转 ...

  9. (转)dp动态规划分类详解

    dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...

最新文章

  1. Windows 软件推荐2020
  2. 从源码编译InfluxDB
  3. python计时器代码_用Python写计时器
  4. mysql 定时脚本_MySQL定时执行脚本(计划任务)命令实例
  5. 两天学会css基础(一)
  6. VLOOKUP函数返回查询值左侧的数据
  7. 怎样选择图纸加密软件?
  8. 网吧操作系统制作与优化
  9. 用计算机画图截图图片,电脑怎么截图
  10. MSU转Uniprot转Entrez ID
  11. 数组取交集、并集与补集
  12. mac pro词典无法使用问题
  13. AWS实例修改时区及数据库实例修改时区
  14. 架构 和 构架 定义
  15. Docker设置共享文件夹
  16. 英语单词音近形似转化规律研究
  17. Ubuntu文件管理快捷键
  18. 甜品消消乐知识点总结
  19. (六)sql事务的处理commit,rollback的用法总结
  20. 世界女性科技群落(五):数字化黄金时代,东南亚女性都是隐藏的阿尔法

热门文章

  1. 谷歌浏览器同步功能无法加载_谷歌浏览器Chrome 86正式发布,全新重磅功能上线——密码检查...
  2. 回顾 | Alibaba Cloud Native Day 杭州场圆满结束(附 PPT 下载)
  3. 使用Java进行查询hugegraph_HugeGraph Examples
  4. shell调用python函数 参数 返回_Python之系统shell交互(subprocess)
  5. 惠普的服务器改win7系统,惠普(HP)笔记本预装Win8改Win7系统BIOS设置教程
  6. html中实现th标签添加分页,html – 如何在Angular 4中为表添加分页?
  7. mysql数据类型查询命令_Linux命令:MySQL系列之三--mysql数据类型及SQL结构化查询语句使用...
  8. python查看类的属性和方法_Python 获取对象的属性和方法—dir 函数
  9. java 内部类怎么new_[转]【Java】内部类(Inner Class)如何创建(new)
  10. ajax form表单提交_开发日志:金数据表单自动提交脚本