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. Android -- 使用图库文件并可以裁剪文件(ImageView)

    1. 本例子首先教大家如何打开图库 ,然后在使用裁剪功能,来裁剪图库里面的图片并进行显示工作

  2. IBatis按条件分页查询

    XML中代码  <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC & ...

  3. ThinkPHP 错误: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

    在配置了ThinkPHP 的数据库配置信息后,在实例化Model(),调用相关方法时候 出现错误,改进如下方式后解决: 找到php.ini 的文件,打开扩展  php_pdo_mysql.dll ,然 ...

  4. XSS攻击

    什么是XSS? http://www.cnblogs.com/bangerlee/archive/2013/04/06/3002142.html XSS攻击及防御? http://blog.csdn. ...

  5. 【emWin】例程三:显示方向的切换

    实验指导书及代码包下载: http://pan.baidu.com/s/1pK9o0xP

  6. 配置webdriver环境

    安装环境pip install selenium,提示 Could not find a version that satisfies the requirement selenium (from v ...

  7. LR11破解License

    golba-65000: AEACFSJI-YJKJKJJKEJIJD-BCLBR golba-100: AEAMAUIK-YAFEKEKJJKEEA-BCJGI web-10000: AEABEXF ...

  8. Android 操作系统的内存回收机制(转载)

    Android 操作系统的内存回收机制(转载) Android APP 的运行环境 Android 是一款基于 Linux 内核,面向移动终端的操作系统.为适应其作为移动平台操作系统的特殊需要,谷歌对 ...

  9. 网络编程学习笔记:linux下的socket编程

    socket是进程通信的一种方式,通过调用一些API可以实现进程间通信,建立连接以及收发信息的过程如下图所示: 这些函数的用法如下: 1.int socket(int protocolFamily, ...

  10. iOS10 导航条,这个二狗子变了...踩坑

    1.iOS10导航透明要转换一个透明image UIImage *image = IsDeviceVersionIOS10 ? [WeUtils imageWithColor:[UIColor cle ...