HDOJ 1171 Big Event in HDU
背包模版:
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
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).
A test case starting with a negative integer terminates input and this test case is not to be processed.
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相关推荐
- DP Big Event in HDU
Big Event in HDU Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) T ...
- Big Event in HDU
提供多重背包的一些思路 Description Nowadays, we all know that Computer College is the biggest department in HDU ...
- HDU1171-Big Event in HDU
描述: Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don ...
- 动态规划题目——背包
背包问题 1. 01背包 [HDOJ 2955.Robberies] [HDOJ 1203.I NEED A OFFER!] [HDOJ 1864.最大报销额] 2. 完全背包 [HDOJ 2159. ...
- 杭电OJ分类题目(1)
原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...
- 两条直线的交点 c语言,计算两条直线的交点(C#)
PS:从其他地方看到的源码是有问题的.下面是修正后的 /// /// 计算两条直线的交点 /// /// L1的点1坐标 /// L1的点2坐标 /// L2的点1坐标 /// L2的点2坐标 /// ...
- 动态规划总结与题目分类
源博客链接:http://blog.csdn.net/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少 ...
- dp进阶之FFT加速+数据结构优化+不等式优化
快速傅里叶变换 快速傅里叶变换(英语:Fast Fourier Transform, FFT),是快速计算序列的离散傅里叶变换(DFT)或其逆变换的方法.傅里叶分析将信号从原始域(通常是时间或空间)转 ...
- (转)dp动态规划分类详解
dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...
最新文章
- Windows 软件推荐2020
- 从源码编译InfluxDB
- python计时器代码_用Python写计时器
- mysql 定时脚本_MySQL定时执行脚本(计划任务)命令实例
- 两天学会css基础(一)
- VLOOKUP函数返回查询值左侧的数据
- 怎样选择图纸加密软件?
- 网吧操作系统制作与优化
- 用计算机画图截图图片,电脑怎么截图
- MSU转Uniprot转Entrez ID
- 数组取交集、并集与补集
- mac pro词典无法使用问题
- AWS实例修改时区及数据库实例修改时区
- 架构 和 构架 定义
- Docker设置共享文件夹
- 英语单词音近形似转化规律研究
- Ubuntu文件管理快捷键
- 甜品消消乐知识点总结
- (六)sql事务的处理commit,rollback的用法总结
- 世界女性科技群落(五):数字化黄金时代,东南亚女性都是隐藏的阿尔法
热门文章
- 谷歌浏览器同步功能无法加载_谷歌浏览器Chrome 86正式发布,全新重磅功能上线——密码检查...
- 回顾 | Alibaba Cloud Native Day 杭州场圆满结束(附 PPT 下载)
- 使用Java进行查询hugegraph_HugeGraph Examples
- shell调用python函数 参数 返回_Python之系统shell交互(subprocess)
- 惠普的服务器改win7系统,惠普(HP)笔记本预装Win8改Win7系统BIOS设置教程
- html中实现th标签添加分页,html – 如何在Angular 4中为表添加分页?
- mysql数据类型查询命令_Linux命令:MySQL系列之三--mysql数据类型及SQL结构化查询语句使用...
- python查看类的属性和方法_Python 获取对象的属性和方法—dir 函数
- java 内部类怎么new_[转]【Java】内部类(Inner Class)如何创建(new)
- ajax form表单提交_开发日志:金数据表单自动提交脚本