• HDU 2602 Bone Collector


    Bone Collector

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 7774 Accepted Submission(s): 2884


    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 …
    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 231).

    Sample Input

    1
    5 10
    1 2 3 4 5
    5 4 3 2 1

    Sample Output

    14

    Author

    Teddy

    Source

    Recommend

    lcy
     1 #include<stdio.h>
    2 #include<string.h>
    3 #include<stdlib.h>
    4 #define max 1010
    5 struct bone
    6 {
    7 int ve , value ;
    8 }num[max] ;
    9 int T , N , V , Mv[max] ;
    10 int MAX ( int a , int b )
    11 {
    12 return a > b ? a : b ;
    13 }
    14
    15 int main ()
    16 {
    17 scanf ( "%d" , &T ) ;
    18 while ( T -- ) {
    19 scanf ( "%d%d" , &N , &V ) ;
    20 for ( int i = 1 ; i <= N ; i ++ )
    21 scanf ( "%d" , &num[i].value ) ;
    22 for ( int i = 1 ; i <= N ; i ++ )
    23 scanf ( "%d" , &num[i].ve ) ;
    24 for ( int i = 0 ; i <= V ; i ++ )
    25 Mv[i] = 0 ;
    26 for ( int i = 1 ; i <= N ; i ++ )
    27 for ( int j = V ; j >= num[i].ve ; j -- )
    28 Mv[j] = MAX ( Mv[j] , Mv[j - num[i].ve] + num[i].value ) ; // 状态方程
    29 printf ( "%d\n" , Mv[V] ) ;
    30 }
    31 return 0 ;
    32 }

      

  • 相关阅读:
    ubuntu sudo apt-get update 失败 解决方法
    Table 'performance_schema.session_variables' doesn't exist
    进程间的几种通信方式
    linux优先级、性能监控指令
    chmod修改文件的权限/chown修改文件和目录的所有者
    Akka学习博客
    RFID Hacking③:使用ProxMark3嗅探银行闪付卡信息
    技术分享:逆向破解华为路由器第二部分
    玩转无线电 -- 温哥华天车 RFID 票务系统
    自己搭建Wifi Pineapple Mark V
  • 原文地址:https://www.cnblogs.com/jbelial/p/2131060.html
Copyright © 2020-2023  润新知