基础-DP
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
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
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的更多相关文章
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
- 基础DP(初级版)
本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- M - 基础DP
M - 基础DP Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descriptio ...
- lightoj1004【基础DP】
从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...
- 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 ...
随机推荐
- Python for Informatics 第11章 正则表达式六(译)
注:文章原文为Dr. Charles Severance 的 <Python for Informatics>.文中代码用3.4版改写,并在本机测试通过. 11.7 调试 Python有一 ...
- PHP+MySQL+Easyui tree菜单从后台加载json数据(一)
实现功能:从数据库加载出所有的数据库名,相应的数据库加载对应的数据库表名 原理:(首先看一下参考手册的内容) 异步加载Tree tree 支持内置的异步加载模式,用户创建一个空的tree,然后定义一个 ...
- bzoj3212 pku3468 A Simple Problem with Integers
一个有初值的数列.区间加.区间查 用线段树直接水过 然而并没有1A,主要是做题太快没看规模结果没注意线段树要用longlong建 卧槽怎么可以这么坑爹,害得我看见wa心慌了,还以为连线段树都要跪 一开 ...
- C#自定义控件属性显示在属性面板中操作
private Color controleColor; [Browsable(true)] [Description("控件颜色"), Category("自定义&qu ...
- 如何在CentOS/RHEL & Fedora上安装MongoDB 3.2
MongoDB(名称取自"huMONGOus")是一个有着全面灵活的索引支持和丰富的查询的数据库.MongoDB通过GridFS提供强大的媒体存储.点击这里获取MongoDB的更多 ...
- mongoose连接collection后自动加s的问题
这两天折腾mongoose,发现数据成功写入集合了,但是在Terminal查询的时候却查不到 于是show collections后发现在原来的集合底下,又生成了一个加了s的集合,shenmegui ...
- Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...
- 用Struts2拦截器实现文件下载前的验证
思想:用户登录后,将登录信息存储在session中,每次需要验证时,取出来验证 缺陷:没有实现多用户登录时的情况 实行步骤: 登录信息的存储: ActionContext actionContext ...
- ubuntu segmentation fault 段错误
1.段错误 http://www.cnblogs.com/panfeng412/archive/2011/11/06/2237857.html 2.段错误的调试方法 2.1使用printf输出信息 2 ...
- ComboSelect 下拉筛选
Jquery Combo Select下拉筛选 http://www.dowebok.com/179.html