hdu2602 Bone Collector

题意:经典的01背包题,给出了石头的数量与背包的容量,然后分别给出每个石头的容量与价值,要求最优解,可以说是01背包果题。

http://acm.hdu.edu.cn/showproblem.php?pid=2602

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

struct hdu2602{
    int val;
    int v;
}a[1010];

int main(){
    int T,n,v;
    scanf("%d",&T);
    int dp[1010];
    while(T--){
        cin >> n >> v;
        for(int i=1;i<=n;i++)
            cin >> a[i].val;
        for(int i=1;i<=n;i++)
            cin >> a[i].v;
        memset(dp,0,sizeof(dp));

        int ans=0;
        for(int i=1;i<=n;i++)
            for(int j=v;j>=a[i].v;j--)
                dp[j]=max(dp[j],dp[j-a[i].v]+a[i].val);

        printf("%d\n",dp[v]);
    }
    return 0;
}
时间: 2024-11-02 23:03:19

hdu2602 Bone Collector的相关文章

hdu2602 Bone Collector (01背包)

本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //============================================================================ // Name : 2602.cpp // Author : vit // Version : // Copyright : Your copyright notice // Description : Hello

HDU2602 Bone Collector 【01背包】

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28365    Accepted Submission(s): 11562 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

hdu2602 Bone Collector(背包问题)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 39612    Accepted Submission(s): 16412 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

【模板--完全背包】HDU--2602 Bone Collector

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 volum

0-1背包问题(经典)HDU2602 Bone Collector

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 36479    Accepted Submission(s): 15052 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bon

【HDU2602】Bone Collector(01背包)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 38586    Accepted Submission(s): 16007 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

hdu2602 01背包Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40316    Accepted Submission(s): 16748 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone Collector&qu

Bone Collector

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

Bone Collector(杭电2602)(01背包)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 31604    Accepted Submission(s): 13005 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo