dp之多重背包2191
水题........
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int s[2000][2],dp[150],t[150][3];
int main()
{
int text;
scanf("%d",&text);
while(text--)
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d %d %d",&t[i][0],&t[i][1],&t[i][2]);
int cnt=0;
for(int i=1;i<=m;i++)
{
int k=1;
while(t[i][2]-k>0)
{
s[cnt][0]=k*t[i][0];
s[cnt++][1]=k*t[i][1];
t[i][2]-=k;
k*=2;
}
s[cnt][0]=t[i][2]*t[i][0];
s[cnt++][1]=t[i][2]*t[i][1];
}
memset(dp,0,sizeof(dp));
for(int i=0;i<cnt;i++)
{
for(int j=n;j>=s[i][0];j--)
if(dp[j]<dp[j-s[i][0]]+s[i][1])
dp[j]=dp[j-s[i][0]]+s[i][1];
}
printf("%d\n",dp[n]);
}
return 0;
}
dp之多重背包2191的更多相关文章
- 单调队列优化DP,多重背包
单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...
- dp之多重背包poj2392
题意:有k种石头,高为hi,在不超过ai的高度下,这种石头可以放置,有ci种这个石头,求这些石头所能放置的最高高度......... 思路:以往的什么硬币种数,最大硬币数之类的,他们的硬币都已经是排好 ...
- dp之多重背包hdu1059
题意:价值为1,2,3,4,5,6. 分别有n[1],n[2],n[3],n[4],n[5],n[6]个.求能否找到满足价值刚好是所有的一半的方案. 思路:简单的多重背包,我建议多重背包都用二进制拆分 ...
- nyoj 546——Divideing Jewels——————【dp、多重背包板子题】
Divideing Jewels 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Mary and Rose own a collection of jewells. ...
- dp之多重背包(二进制优化)
void solve(int v,int w,int c){ int count=0; for(int k=1;k<=c;k<<=1) { val[c ...
- 硬币问题 (dp,多重背包的二分优化)
题目描述 给你n种硬币,知道每种的面值Ai和每种的数量Ci.问能凑出多少种不大于m的面值. 输入 有多组数据,每一组第一行有两个整数 n(1≤n≤100)和m(m≤100000),第二行有2n个整数, ...
- hdu1059&poj1014 Dividing (dp,多重背包的二分优化)
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- [DP之多重背包优化方法]
首先我们看一道有趣的题目 然后这道题很快想到是一个多重背包和无限背包混合体 那么我们就以这道题 来讨论一下多重背包的优化 首先我们看看朴素打法 memset(F,,]=; ;i<=N;i++) ...
- poj 1742 Coins(dp之多重背包+多次优化)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
随机推荐
- Sqlite清空表数据
delete from TableName; //清空数据 where name ='TableName';//自增长ID为0
- jquery easyui validatebox remote使用
validatebox 的validateType可以是一下3个格式: 1字符串 2数组,应用多个验证 3对象,每个key是一个验证名称value是验证的数组参数 下面是代码示例 <input ...
- (笔试题)数组A中任意两个相邻元素大小相差1,在其中查找某个数。
题目: 数组A中任意两个相邻元素大小相差1,现给定这样的数组A和目标整数t,找出t在数组A中的位置.如数组:[1,2,3,4,3,4,5,6,5],找到4在数组中的位置. 思路: 很明显,在数组中寻找 ...
- ireport制作报表pageheader只在第一页出现的解决办法
这问题居然没找到解决办法..... 好吧,那我自己解决..... 其实很简单..... 只要打开ireport,pageheader的属性,在print when expression设置$V{PAG ...
- 你们对LinearLayout线性布局中Layout_weight的误解
帮人找个入门级别的书得负责任,自己先看一下有无缺陷,结果发现这个:(原文发在该书的论坛上,发现受众面太小了,无奈转到这个弃用很久的博客里,以后把心得慢慢发上来) Google Android开发入门与 ...
- 算法笔记_129:计数排序(Java)
目录 1 问题描述 2 解决方案 2.1比较计数排序 2.2 分布计数排序 1 问题描述 给定一组数据,请使用计数排序,得到这组数据从小到大的排序序列. 2 解决方案 2.1比较计数排序 下面算法 ...
- WCF学习笔记之序列化
DataContractAttribute 与 DataMenberAttribute DataContractAttribute该特性只能用于枚举.类和结构体,而不能用于接口:又因为DataCont ...
- javascript 新知识
document.compatMode 属性 BackCompat: Standards-compliant mode is not switched on. (Quirks Mode) 标准模式 ...
- eclipse如何优化构建的速度
eclipse如何优化构建的速度(Building) - AlanLee(Java) - 博客园 http://www.cnblogs.com/AlanLee/p/5383166.html
- 【LeetCode】111. Minimum Depth of Binary Tree (2 solutions)
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...