2016SDAU编程练习三1017
来源:互联网 发布:铁岭网络预约出租汽车 编辑:程序博客网 时间:2024/05/22 03:02
Problem Description
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 …<br>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 ?<br><center><img src=../../../data/images/C154-1003-1.jpg> </center><br>
Input
The first line contain a integer T , the number of cases.<br>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<sup>31</sup>).
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
题意:背包价值最大
思路:背包问题
感想:DP真是无处不在啊
AC代码:
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
//freopen("r.txt","r",stdin);
int T,n,Vol,i,j;
int a;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&Vol);
int val[1005];
int vol[1005];
int dp[1005];
for(i=1;i<=n;i++)
{
scanf("%d",&val[i]);
}
for(i=1;i<=n;i++)
{
scanf("%d",&vol[i]);
}
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
{
for(j=Vol;j>=vol[i];j--)
{
dp[j]=max(dp[j],dp[j-vol[i]]+val[i]);
}
}
cout<<dp[Vol]<<endl;
}
}
- 2016SDAU编程练习三1017
- 2016SDAU编程练习三1001
- 2016SDAU编程练习三1002
- 2016SDAU编程练习三1006
- 2016SDAU编程练习三1010
- 2016SDAU编程练习三1011
- 2016SDAU编程练习三1012
- 2016SDAU编程练习三1013
- 2016SDAU编程练习三1014
- 2016SDAU编程练习三1015
- 2016SDAU编程练习三1016
- 2016SDAU编程练习三1018
- 2016SDAU编程练习三1023
- 2016SDAU编程练习三1004
- 2016SDAU编程练习三1007
- SDAU练习三1017
- 2016sdau课程练习专题三 1017
- 2016SDAU编程练习二1017
- python执行系统命令的方法 :os.system(),subprocess.popen(),commands
- DuiLib CreateControl
- 【Android】Activity的启动模式
- 随笔1:shell递归遍历文件夹
- mysql-创建用户报错ERROR 1396 (HY000): Operation CREATE USER failed for 'XXXX'@'XXXX'
- 2016SDAU编程练习三1017
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- 二分查找算法
- 惊心动魄-微信抢红包传播活动
- 删除list中元素
- 1.C++--关于文件间共享代码的方法
- Socket编程------模拟QQ聊天(TCP)
- POJ 1066 Treasure Hunt(转化线段相交)
- Android Animation动画(Frame-By-Frame Animations 、Tween Animations 、Property Animation)的详解