Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … 
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ? 

Input

The first line contain a integer T , the number of cases. 
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.

Output

One integer per line representing the maximum of the total value (this number will be less than 2 31).

Sample Input

1
5 10
1 2 3 4 5
5 4 3 2 1

Sample Output

14
#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#define maxn 100000
long long d[maxn+];
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int main()
{
int t,n,m,i,j;
int V[],N[];
cin>>t;
while(t--)
{
memset(d,,sizeof(d));
cin>>n>>m;
for(i=;i<n;i++)
cin>>V[i];
for(j=;j<n;j++)
cin>>N[j];
for(i=;i<n;i++)
for(j=m;j>=N[i];j--)
{
d[j]=max(d[j],d[j-N[i]]+V[i]);
}
cout<<d[m]<<endl;
}
return ;
}

基础-DP的更多相关文章

  1. 基础dp

    队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...

  2. 基础DP(初级版)

    本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...

  3. hdu 5586 Sum 基础dp

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...

  4. hdu 4055 Number String (基础dp)

    Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...

  6. 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)

    layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...

  7. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

  8. M - 基础DP

    M - 基础DP Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descriptio ...

  9. lightoj1004【基础DP】

    从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...

  10. hdu 4489 The King’s Ups and Downs(基础dp)

    The King’s Ups and Downs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

随机推荐

  1. HDU1003 简单DP

    Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the ...

  2. 所有的畅通工程[HDU1232][HDU1874][HDU1875][HDU1879]

    畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...

  3. .NET面试题目

    简单介绍下ADO.NET和ADO主要有什么改进? 答:ADO以Recordset存储,而ADO.NET则以DataSet表示,ADO.NET提供了数据集和数据适配器,有利于实现分布式处理,降低了对数据 ...

  4. 序列流 SequenceInputStream

    SequenceInputStream:序列流,对多个流进行合并. SequenceInputStream 表示其他输入流的逻辑串联.它从输入流的有序集合开始,并从第一个输入流开始读取,直到到达文件末 ...

  5. 温故而知新 兼容性较强的轮播器superslide.js

    官网: http://www.superslide2.com/index.html demo: http://www.superslide2.com/demo.html API: http://www ...

  6. supercool.sh文件里,有哪些恶意的命令

    当你在一个bash命令行中输入"*"时,bash会扩展到当前目录的所有文件,然后将他们全部作为参数传递给程序.例如:rm *,将会删除掉当前目录的所有文件. 0x01 文件名被当做 ...

  7. 20145205《Java程序设计》第四次实验:Android环境搭建

    实验内容 1.搭建Android环境 2.运行Android 3.修改代码,能输出学号 实验步骤 搭建Android环境 安装Android,核心是配置JDK.SDK 运行Android 总结感想: ...

  8. 动态加载多国语言 ---- cookie + 浏览器

    一.多国语言缩写列表 因为涉及到浏览器的可接收语言,所以需要知道各个国家的语言缩写. 这个百度一下即可. en 英文 en_US 英文 (美国) ar 阿拉伯文 ar_AE 阿拉伯文 (阿拉伯联合酋长 ...

  9. PBOC2.0中消费交易流程

    消费交易允许持卡人使用电子存折或电子钱包的余额进行购物或获取服务.此交易可以在销售点终端(POS)上脱机进行.使用电子存折进行的消费交易必须提交个人识别码(PIN),使用电子钱包则不需要. 1.1 终 ...

  10. js 图片加载完后的处理事件

    //图片加载完成后再显示页面 document.getElementById('icon').onload=function(){ document.getElementById('wrap').st ...