链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191

思路:多重背包模板题

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int money,type;
int price[],weigh[],num[],dp[];
int max(int a,int b)
{
return a>b?a:b;
}
void CompletePack(int price,int weigh)
{
for(int i=price;i<=money;i++)
dp[i]=max(dp[i],dp[i-price]+weigh);
}
void ZeroOnePack(int price,int weigh)
{
for(int i=money;i>=price;i--)
dp[i]=max(dp[i],dp[i-price]+weigh);
}
void MultiplePack(int price,int weigh,int num)
{
if(price*num>=money)
CompletePack(price,weigh);
int k=;
while(k<num)
{
ZeroOnePack(k*price,k*weigh);
num-=k;
k>>;
}
ZeroOnePack(num*price,num*weigh);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&money,&type);
memset(dp,,sizeof(dp));
for(int i=;i<=type;i++)
{
scanf("%d %d %d",&price[i],&weigh[i],&num[i]);
MultiplePack(price[i],weigh[i],num[i]);
}
printf("%d\n",dp[money]);
}
return ;
}

最新文章

  1. 【HanLP】资料链接汇总
  2. .net学习笔记---tcp/udp/http/socket
  3. 东大OJ-双塔问题
  4. Mysql之取消主从复制
  5. JAVA基础知识之IO——Java IO体系及常用类
  6. hdu 1561 The more, The Better (树上背包)
  7. iOS开发篇-申请开发者账号流程
  8. XPATH 注入的介绍与代码防御
  9. Qt C++中的关键字explicit——防止隐式转换(也就是Java里的装箱),必须写清楚
  10. oracle监听服务开启
  11. javascript作用域和作用域链
  12. python的内置函数bin()
  13. 最简单的基于FFmpeg的封装格式处理:视音频分离器(demuxer)
  14. python - 递归 二分法
  15. CF 1013E Hills
  16. Html块标签、含样式的标签、语义化的标签:
  17. MacBook使用笔记2 - 安装windows虚拟机攻略
  18. CI入门
  19. ARM Cortex-A9 (tiny 4412)
  20. spring 注解@PathVariable

热门文章

  1. Struts2深入学习:OGNL表达式原理
  2. AJAX学习笔记
  3. PowerDesigner连接Oracle并导出表结构
  4. hibernate+mysql的连接池配置
  5. js笔记
  6. 耗时两月,NHibernate系列出炉
  7. 【CentOS7之防火墙命令】
  8. Linux C--信号 sigaction函数
  9. 2016-WAS
  10. easyui的datagrid form(表单)提交到后台转对象的时候中文出现乱码