hdu 2602 01背包入门

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>
#include <cstring>
using namespace std;
struct node
{
    int val;
    int weight;
}a[1010];
int main()
{
    int t;
    int n,v;
    int i,j;
    cin>>t;
    while(t--)
    {
        int dp[1005];//i表示的是重量
        cin>>n>>v;
        for(int i=0;i<n;++i)
            cin>>a[i].val;
        for(int i=0;i<n;++i)
            cin>>a[i].weight;
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;++i)
            for(int j=v;j>=a[i].weight;--j)
            dp[j]=max(dp[j],dp[j-a[i].weight]+a[i].val);
        cout<<dp[v]<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的打砖块游戏(附源代码)   项目:JavaScript 打砖块游戏(附源代码) 打砖块游戏是使用 HTML5、CSS 和 JavaScript 开发的简单项目。这款游戏是关于借助弹跳球和滑动平面来打破障碍。您可以玩游戏,直到能够打破所有砖块而不会将球掉到地上。玩家必须使用箭头键移动滑动平面。 游戏制作 该项目仅包含 HTML、CSS 和 JavaScript。谈到这款游戏的功能,用户必须移动滑动平面以使球反弹回来以打破砖块。球必须接触砖块才能将其打破,并且不应掉落到地上。这款游戏的 PC 控制也很简单。您只需使用左、右、上、下键根据要求移动滑动平面即可。如果玩家能够在 3 次生命中清除所有砖块,则获胜。 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,单击 index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
使用 JavaScript 编写的带有源代码的引文生成器   项目:使用 JavaScript 编写的引文生成器(附源代码) Quote Generator 是一个使用 HTML、CSS 和 JavaScript 开发的简单项目。这是一个简单的励志名言生成器迷你项目。当您单击“ 显示另一个名言” 按钮时,每次单击时您都会看到不同的励志名言。这个项目是一个简单的 JavaScript 项目,用于随机显示励志名言。此外,您可以看到背景颜色随着名言的变化而变化。 关于该项目 这个生成器是一个简单有趣的项目,仅包含 HTML、CSS 和 JavaScript。在这里,用户必须单击“ 显示另一个引文” 按钮,引文就会出现,背景颜色也会发生变化。此外,该项目还包含大量 JavaScript,用于对项目的某些部分进行验证。 如何运行该项目? 要运行此项目,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox  ,以获得更好的性能。要执行该项目,首先,通过单击 index.html 文件在浏览器中打开该项目。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值