水题........

#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的更多相关文章

  1. 单调队列优化DP,多重背包

    单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...

  2. dp之多重背包poj2392

    题意:有k种石头,高为hi,在不超过ai的高度下,这种石头可以放置,有ci种这个石头,求这些石头所能放置的最高高度......... 思路:以往的什么硬币种数,最大硬币数之类的,他们的硬币都已经是排好 ...

  3. dp之多重背包hdu1059

    题意:价值为1,2,3,4,5,6. 分别有n[1],n[2],n[3],n[4],n[5],n[6]个.求能否找到满足价值刚好是所有的一半的方案. 思路:简单的多重背包,我建议多重背包都用二进制拆分 ...

  4. nyoj 546——Divideing Jewels——————【dp、多重背包板子题】

    Divideing Jewels 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 Mary and Rose own a collection of jewells. ...

  5. dp之多重背包(二进制优化)

    void solve(int v,int w,int c){    int count=0;    for(int k=1;k<=c;k<<=1)    {        val[c ...

  6. 硬币问题 (dp,多重背包的二分优化)

    题目描述 给你n种硬币,知道每种的面值Ai和每种的数量Ci.问能凑出多少种不大于m的面值. 输入 有多组数据,每一组第一行有两个整数 n(1≤n≤100)和m(m≤100000),第二行有2n个整数, ...

  7. hdu1059&poj1014 Dividing (dp,多重背包的二分优化)

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

  8. [DP之多重背包优化方法]

    首先我们看一道有趣的题目 然后这道题很快想到是一个多重背包和无限背包混合体 那么我们就以这道题 来讨论一下多重背包的优化 首先我们看看朴素打法 memset(F,,]=; ;i<=N;i++) ...

  9. poj 1742 Coins(dp之多重背包+多次优化)

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

随机推荐

  1. create xml file from sql script

    Declare @xmlDoc xmlSET @xmlDoc = (SELECT * FROM USERS AS UserTable For XML AUTO, ELEMENTS, ROOT('Roo ...

  2. C++primer习题--第4章

    本文地址:http://www.cnblogs.com/archimedes/p/cpp-primer-chapter4-ans.html,转载请注明源地址. [习题 4.7] 编写必要的代码将一个数 ...

  3. html表格内容自动换行

    有时候表格会因为内容多少忽大忽小的很烦人,在网上搜了下解决方案,效果不错哦,给大家分享下!首先介绍两个利器:table-layout:fixed //固定表格大小word-break:break-al ...

  4. Vue组件开发实践之scopedSlot的传递

    收录待用,修改转载已取得腾讯云授权 导语 现今的前端开发都讲究模块化组件化,即把公共的交互和功能封装到一个个的组件之中,在开发整体界面的时候就能像搭积木一样快速清晰高效.在使用Vue开发我们的vhtm ...

  5. [Angular-Scaled Web] 6. Navigating between states with ui-router

    There are two ways to naviagting between state: 1. Using $state service, $state.go() 2. Using ui-ser ...

  6. (剑指Offer)面试题4:替换空格

    题目: 请实现一个函数,把字符串中的每个空格替换成“%20”,例如输入“We are happy”,则输出“We%20are%20happy”. 思路: 背景: 在网络编程中,如果URL参数中含有特殊 ...

  7. vscode - 移动端适配(cssrem)

    建议使用Chrome浏览器. 1.第一步,安装扩展以及配置 2.第二步,使用(记得按一下↓)

  8. 流编辑器sed

    sed与grep一样,都起源于老式的ed编辑器,因其是一个流编辑器(stream editor)而得名.与vi等编辑器不同,sed是一种非交互式编辑器(即用户不必参与编辑过程),它使用预先设定好的编辑 ...

  9. ACM 刷题错误总结 持续更新并持续回想中o(╯□╰)o

    一.段错误/RE 1.& 变量取地址 2.数组越界 3.爆栈, 非常可能是死循环,ruturn的边界没有处理好,或者是递归的内容里有死循环的部分. 4.线段树 逢写必错,都是build(i*2 ...

  10. ‘close’ was not declared in this scope

    ‘close’ was not declared in this scope ‘read’ was not declared in this scope ‘sysconf’ was not decla ...