hdu 1171 Big Event in HDU
来源:互联网 发布:淘宝上的耐克是真的吗 编辑:程序博客网 时间:2024/06/08 11:19
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[2000000],t;void zeroonepack(int cost,int weight){ for(int i=t;i>=cost;i--) { dp[i]=max(dp[i],dp[i-cost]+weight); }}void completepack(int cost,int weight){ for(int i=cost;i<=t;i++) { dp[i]=max(dp[i],dp[i-cost]+weight); }}void multiplepack(int cost,int weight,int amount){ if(amount*cost>=t) completepack(cost,weight); else { int k=1; while(k<amount) { zeroonepack(cost*k,weight*k); amount-=k; k*=2; } zeroonepack(cost*amount,weight*amount); }}int main(){ int n,v,i,j,a[100+5],b[100+5]; while(~scanf("%d",&n)) { if(n<=0) break; v=0; for(i=0;i<n;i++) { scanf("%d %d",&a[i],&b[i]); v+=a[i]*b[i]; } t=v/2; memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) { multiplepack(a[i],a[i],b[i]); } printf("%d %d\n",v-dp[t],dp[t]); } return 0;}
0 0
- 1171 Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- 取数字问题
- linux下uart应用编程
- AFN的使用
- Unity 自动寻路Navmesh之高级主题
- Php基础文件操作
- hdu 1171 Big Event in HDU
- Bestcoders
- CM3 STM32F的低功耗
- jQuery插件开发的五种形态小结
- Unity 自动寻路Navmesh之跳跃,攀爬,斜坡
- 画图解释 SQL join 语句
- usb mtp激活流程
- iOS 使用Quartz 2D画虚线
- 敏捷开发之道