Hodj1171多重背包转换成母函数
来源:互联网 发布:banner.js 韩顺平 编辑:程序博客网 时间:2024/05/16 08:50
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;static const int lmax = 1000000;static int C1[lmax],C2[lmax];static int a[10],e[10];int main(){int n;while(scanf("%d",&n)&&n>=0){int num;int total = 0;for (int i=1;i<=n;++i){scanf("%d %d",&a[i],&e[i]);total += e[i]*a[i];}memset(C1,0,sizeof(C1));memset(C2,0,sizeof(C2));for(int i=0;i<=e[1];++i){C1[i*a[1]] = 1;}for (int i=2;i<=n;++i){//因为A最多选一半for (int j=0;j<=total/2;++j){for (int k=0;k<=e[i]&&(k*a[i]+j)<=total/2;k++){C2[j+k*a[i]]+=C1[j];}}for (int j=0;j<=total/2;++j){C1[j] =C2[j];C2[j] = 0;}}int ans = 0;for (int i=total/2;i>0;i--){if (C1[i]){ans = i;break;}}printf("%d %d\n",total-ans,ans);}return 0;}
0 0
- Hodj1171多重背包转换成母函数
- 多重背包转换成0-1背包
- 多重背包转换成完全背包和01背包
- POJ 1014 Dividing(多重背包转换成01背包)
- hdu1171(母函数或多重背包)
- hdoj 1059 Dividing 【多重背包】 【母函数】
- 多重背包转01背包/母函数(1171)
- HDOJ 1171 Big Event in HDU (多重背包) / (母函数)
- Holding Bin-Laden Captive!(母函数或多重背包)
- Big Event in HDU(多重背包或母函数)
- HDU 1171 Big Event in HDU【多重背包||母函数】
- hdu 2082 找单词(母函数|多重背包)
- hdu 1171 Big Event in HDU(母函数|多重背包)
- hdoj 1059 Dividing 【多重背包】||【优化母函数】
- HDOJ 题目1059Dividing(多重背包,母函数优化)
- hdu1171Big Event in HDU(母函数或多重背包)
- poj 1014 Dividing(多重背包/母函数)
- ZCMU-1381-砝码(母函数、多重背包)
- Mark Knowledge of Java Thread (2): Notify and Wait
- NS3网络仿真(12): ICMPv4协议
- 一道关于try,finally执行顺序的面试题
- oracle下载地址。
- POJ 2752 Seek the Name, Seek the Fame(KMP)
- Hodj1171多重背包转换成母函数
- socket 网络编程快速入门(一)教你编写基于UDP/TCP的服务(客户端)通信
- 二分查找递归和非递归
- Hive日期格式转换用法
- linux下线程的创建
- Light OJ 1120 Rectangle Union(扫面线求面积并)
- HDU 1847 Good Luck in CET-4 Everybody!(SG函数)
- 时间序列相似性搜索总结
- ORM进阶之Hibernate 的三大对象