http://poj.org/problem?id=1276

 #include <stdio.h>
#include <string.h>
const int N=;
#define Max(a,b) (a)>(b)?(a):(b)
int dp[N],cash;
void ZeroOnePack(int cost)//01背包
{
for (int i = cash; i >= cost; i--)
{
dp[i] = Max(dp[i],dp[i-cost]+cost);
}
}
void ComplexPack(int cost)//完全背包
{
for (int i = cost; i <= cash; i++)
{
dp[i] = Max(dp[i],dp[i-cost]+cost);
}
}
void MultiplePack(int cnt,int cost)//多重背包
{
if (cnt*cost > cash)
ComplexPack(cost);
else
{
int k = ;
while(k < cnt)
{
ZeroOnePack(k*cost);
cnt-=k;
k<<=;
}
ZeroOnePack(cnt*cost);
}
}
int main()
{
int n,cost[],cnt[];
while(~scanf("%d %d",&cash,&n))
{
for (int i = ; i <= n; i++)
{
scanf("%d %d",&cnt[i],&cost[i]);
}
memset(dp,,sizeof(dp));
for (int i = ; i <= n; i++)
{
MultiplePack(cnt[i],cost[i]);
}
printf("%d\n",dp[cash]);
}
return ;
}

最新文章

  1. Java数据结构——平衡二叉树的平衡因子(转自牛客网)
  2. LeetCode之387. First Unique Character in a String
  3. HIVE: Transform应用实例
  4. HTML布局篇之双飞翼(圣杯)布局
  5. Visual Studio 2010 更新NuGet Package Manager出错解决办法
  6. python练习程序(c100经典例6)
  7. IDS 日志分析
  8. Layout( 布局)
  9. Linux中yum的安装
  10. jQuery 方法
  11. 解题(DirGraCheckPath--有向图的遍历(深度搜索))
  12. ASP.Net Core2.1中的HttpClientFactory系列二:集成Polly处理瞬态故障
  13. nginx之快速查找配置文件
  14. Ubuntu下安装Goldendict(翻译软件)
  15. Spring Security的几个重要词
  16. Tensorflow Seq2seq attention decode解析
  17. Neural Networks and Deep Learning(week4)Building your Deep Neural Network: Step by Step
  18. sudo控制权限简单用法介绍
  19. Django商城项目笔记No.2项目准备工作
  20. Spring 学习02

热门文章

  1. CNN结构:Windows使用FasterRCNN-C++版本
  2. Ubuntu用户自定义脚本开机启动
  3. Python 之__slots__的作用
  4. PHP 之中文转为拼音
  5. python包与模块
  6. python合并多个txt文件成为一个文件
  7. adjtimex修改tick值用法举例
  8. [系统资源攻略]CPU使用率和负载
  9. 总结这几天js的学习内容
  10. TCP/IP UDP 协议首部及数据进入协议栈封装的过程