博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
背包问题简单整理
阅读量:7174 次
发布时间:2019-06-29

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

 

hdu2546,01背包,需要有点变形,计算时需要把价格最大的菜先放一边,最后计算。

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int V;int dp[1200];void ZeroOnePack(int ci,int wi){ for(int v=V-5;v>=ci;--v) dp[v] = max(dp[v],dp[v-ci]+wi);}int main(){ //freopen("test.txt","r",stdin); int n; while(true) { scanf("%d",&n); if(n==0) break; memset(dp,0,sizeof(dp)); int vi[1200]; int iMaxIndex = 0; int iMaxVal = -10; for(int i=0;i
View Code

 

hdu 2191 多重背包,多重背包主要可以分解成01背包和完全背包。

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int V,n;int dp[200];void ZeroOnePack(int vi,int wi){ for(int v=V;v>=vi;--v) dp[v] = max(dp[v],dp[v-vi]+wi);}void CompletePack(int vi,int wi){ for(int v=vi;v<=V;++v) dp[v] = max(dp[v],dp[v-vi]+wi);}void MultiPack(int vi,int wi,int ki){ if(vi*ki >= V) { CompletePack(vi,wi); } else { for(int k=1;k
View Code

 

转载于:https://www.cnblogs.com/jlyg/p/10353142.html

你可能感兴趣的文章
.net开源CMS系统使用教程之:如何用We7 CMS建设全新网站
查看>>
查看表扫描次数,并对比索引对表查询的作用
查看>>
Java多线程系列目录(共43篇)
查看>>
解决MySQL登录ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor)问题
查看>>
未排序数组中累加和为给定值的最长子数组长度
查看>>
在linux中安装memcache服务器
查看>>
python之if测试
查看>>
电脑操作的“奇技淫巧”
查看>>
遍历DOM树,each()遍历
查看>>
手势UIGestureRecognizer
查看>>
mongo 手册阅读笔记
查看>>
viewport ——视区概念
查看>>
情商的管理
查看>>
页面跳转到Area区域连接
查看>>
拓扑规则翻译函数(转)
查看>>
[转载]SVN使用教程
查看>>
android 获取所有SD卡目录
查看>>
A trick in loading Fixture to test django application
查看>>
经典SQL语句
查看>>
canvas 画椭圆
查看>>