zoukankan      html  css  js  c++  java
  • HDU

    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 … 
    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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602

    ********************************************

    分析:背包模型

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <cmath>
     6 #include <stack>
     7 #include <map>
     8 #include <vector>
     9 using namespace std;
    10 
    11 #define N 2500
    12 #define INF 0x3f3f3f3f
    13 
    14 int p[N],v[N],dp[25000];
    15 
    16 int main()
    17 {
    18     int T,n,m,i,j;
    19 
    20     scanf("%d", &T);
    21 
    22     while(T--)
    23     {
    24         memset(dp,0,sizeof(dp));
    25 
    26         scanf("%d %d",&n, &m);
    27 
    28         for(i=1;i<=n;i++)
    29             scanf("%d", &p[i]);
    30         for(i=1;i<=n;i++)
    31             scanf("%d", &v[i]);
    32 
    33         for(i=1;i<=n;i++)
    34             for(j=m;j>=v[i];j--)
    35             dp[j]=max(dp[j],dp[j-v[i]]+p[i]);
    36 
    37         printf("%d
    ", dp[m]);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    leetcode(85)最大矩形
    红黑树
    查询学生成绩表中大于60分的每一个成绩的人数
    聚合函数以及SQL中的一些小知识
    Oracle的JDBC
    StringBuffer的reverse方法
    查询时报第一页没有数据,第二页有数据的异常
    普通人如何从平庸到优秀,在到卓越
    HDMI、DVI、VGA等这些接口
    显卡上的VGA接口和高清接口有什么区别?
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5775306.html
Copyright © 2011-2022 走看看