博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 2191 (多重背包二进制优化)
阅读量:4701 次
发布时间:2019-06-09

本文共 843 字,大约阅读时间需要 2 分钟。

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

实现代码:

#include
using namespace std;const int M = 1e5+10;int dp[M];struct node{ int w,v;}lis[M];int main(){ int t,n,m,p,h,c,idx; cin>>t; while(t--){ idx = 0; cin>>n>>m; memset(dp,0,sizeof(dp)); for(int i = 1;i <= m;i ++){ cin>>p>>h>>c; int k = 1; while(c - k>0){ c -= k; lis[++idx].w = k*h; lis[idx].v = k*p; k*=2; } lis[++idx].w = c*h; lis[idx].v = c*p; } for(int i = 1;i <= idx;i ++){ for(int j = n;j >= lis[i].v;j --){ dp[j] = max(dp[j],dp[j-lis[i].v]+lis[i].w); } } cout<
<

 

转载于:https://www.cnblogs.com/kls123/p/10678496.html

你可能感兴趣的文章
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
memcached 细究(三)
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
webservice整合spring cxf
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>
不把DB放进容器的理由
查看>>
OnePage收集
查看>>
Java parseInt()方法
查看>>
yahoo的30条优化规则
查看>>
[CCF2015.09]题解
查看>>
[NYIST15]括号匹配(二)(区间dp)
查看>>
json_value.cpp : fatal error C1083: 无法打开编译器生成的文件:No such file or directory
查看>>
洛谷 P1101 单词方阵
查看>>
Swift DispatchQueue
查看>>