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