基础-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 ...
随机推荐
- Android 高亮显示文本中的关键字
总结:SpannableString用好,可以各种替换Span来操作各种内容 1.文本关键字高亮关键在于:SpannableString使用 主要就是通过关键字在文本的开始index,结束index来 ...
- DOTA 2 Match History WebAPI(翻译)
关于DOTA 2 Match History WebAPI 的 源网页地址: http://dev.dota2.com/showthread.php?t=47115 由于源网页全英文,这边做下翻译方便 ...
- Python In Action:三、稍稍扩展
#!/usr/bin/env python """Spare.py is a starting point for simple wxPython programs.&q ...
- Android 四大护法之一 Service
1.Service的概念 Service是Android 四大组件之一,是默认没有界面的运行于后台的服务程序.Service的开启方式分为启动式服务(startService)和绑定式服务(bindS ...
- C 格式输出
1 一般格式 printf(格式控制,输出表列) 例如:printf("i=%d,ch=%c\n",i,ch); 说明: (1) “格式控制”是用双撇号括起 ...
- amCharts图表组件
amCharts提供了JavaScript/HTML5 Charts.Javascript/HTML5 Stock Chart.JavaScript Maps三种图表组件.amCharts图形效果炫丽 ...
- IOS 开发教程
http://www.raywenderlich.com/category/ios http://www.raywenderlich.com/50310/storyboards-tutorial-in ...
- SQL语句 - MERGE INTO 、Cross/Outer Apply用法理解
MERGE INTO 语法: MERGE INTO table_name alias1 USING (table|view|sub_query) alias2ON (join condition) W ...
- JSON字符串与JSON对象的区别
Q:什么是"JSON字符串",什么是"JSON对象",两者的区别? a.JSON对象是直接可以使用JQuery操作的格式,如C#中可以用对象(类名)点出属性(方 ...
- docker好文收藏
深入浅出Docker(一):Docker核心技术预览 2. 核心技术预览 Docker核心是一个操作系统级虚拟化方法, 理解起来可能并不像VM那样直观.我们从虚拟化方法的四个方面:隔离性.可配额/可度 ...