51nod 1086 背包问题 V2
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1086
思路 裸的多重背包 巩固一下刚学的骚操作
#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
int w[maxn],p[maxn],c[maxn];//分别表示 体积 价值和数量
int dp[]; int main ()
{
int n,W;
cin >> n >> W;
for(int i=;i<=n;i++)
cin>>w[i]>>p[i]>>c[i];
for(int i=;i<=n;i++)
{
if(w[i]*c[i] > W)//完全背包
{
for(int j=w[i];j <= W;j++)
dp[j] = max(dp[j],dp[j-w[i]]+p[i]);
}
else
{
int k=,t=c[i];
while (t>k)
{
for(int j=W;j >= w[i]*k;j--)
dp[j] = max(dp[j],dp[j-w[i]*k]+k*p[i]);
t-=k,k*=;
}
for(int j=W;j>=w[i]*t;j--)
dp[j] = max(dp[j],dp[j-w[i]*t]+t*p[i]);
}
}
cout<<dp[W]<<endl;
}
51nod 1086 背包问题 V2的更多相关文章
- 51nod 1086 背包问题 V2 【二进制/多重背包】
1086 背包问题 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放 ...
- 51nod 1086背包问题V2 (完全背包模板题)
1086 背包问题 V2 1 秒 131,072 KB 20 分 3 级题 题目描述 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1, ...
- 51nod 1086 背包问题 V2(二进制优化多重背包)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1086 题解:怎么用二进制优化多重背包,举一个例子就明白了. ...
- 51Nod:1086背包问题 V2
1086 背包问题 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里 ...
- 51nod1086 背包问题 V2
我都快不会写二进制优化多重背包了...卡了一下常数从rank100+到20+... #include<cstdio> #include<cstring> #include< ...
- 51nod——1086、1257背包问题V2(多重背包二进制拆分转01) V3(分数规划+二分贪心)
V3其实和dp关系不大,思想挂标题上了,丑陋的代码不想放了.
- AC日记——背包问题 V2 51nod 1086
有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi ...
- 51nod 1257 背包问题 V3
1257 背包问题 V3 基准时间限制:3 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 N个物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2.. ...
- 51nod 多重背包问题(动态规划)
多重背包问题 一个背包,承量有限为W,有n种物体,第i种物体,价值Vi,占用重量为 Wi,且有Ci件,选择物品若干放入背包,使得总重量不超过背包的承重.总价值最大? 输入 第1行,2个整数,N和W中间 ...
随机推荐
- 迁移到 Linux :入门介绍 | Linux 中国
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/F8qG7f9YD02Pe/article/details/79001952 这个新文章系列将帮你从其 ...
- PAT 1072 Gas Station[图论][难]
1072 Gas Station (30)(30 分) A gas station has to be built at such a location that the minimum distan ...
- Andrew Ng-ML-第十五章-降维
1.数据压缩 数据压缩不仅能够减小存储空间,并且能够加速学习算法.那么什么是数据压缩呢?下面给出了一个简单的例子: 图1.数据压缩的概念 举了两个例子,一个是横轴x1是厘米,纵轴特征x2是英尺,这明显 ...
- [LeetCode]94, 144, 145 Binary Tree InOrder, PreOrder, PostOrder Traversal_Medium
Given a binary tree, return the inorder, preorder, postorder traversal of its nodes' values. Example ...
- [LeetCode] 102. Binary Tree Level Order Traversal_Medium tag: BFS
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- SpringMyBatisDay03
1.Spring MVC 1)什么是Spring MVC Spring MVC是Spring框架中一个模块,实现MVC结构,便于简单,快速开发MVC结构的WEB应用,Spring MVC提供的API封 ...
- js里实现给数字加三位一逗号间隔的两种方法
方法一: <script type= "text/javascript"> var num_s = "1232134456.546 ";ale ...
- 3/5/2014 cfb 小心
During each move the player can choose all lines of the matrix where dwarf is not on the cell with c ...
- Linux服务器---网络配置
禁止ping 有些时候为了保护主机,会禁止其他机器对主机进行ping操作.Ping命令用的是ICMP协议,只要禁用ICMP协议,那么ping方法就无法检测这台主机.关于ICMP协议的配置文件是“/pr ...
- Jquery图片上传组件,支持多文件上传
Jquery图片上传组件,支持多文件上传http://www.jq22.com/jquery-info230jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传.取消. ...