苏州大学新生寒假训练day3 D - Bone Collector

news/2024/7/3 18:24:40

苏州大学新生寒假训练day3 D - Bone Collector

Problem:

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

很明显的01背包问题,默认了每一个骨头都是独一无二的,注意数据的多组数据即可,01背包的矩阵dp问题在我的其它blog里也有的。最近在学dp多刷一刷。

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    long long n;
    cin>>n;

    while(n--)
    {
        long long a;
        long long size;

        cin>>a>>size;
        long long v[100000];
        long long w[100000];
        long long dp[100000];
        memset(v,0,sizeof(v));
        memset(w,0,sizeof(w));
        memset(dp,0,sizeof(dp));
        for(int i = 1;i <= a;i++)
        {
            cin>>v[i];
        }
        for(int i = 1;i <= a;i++)
        {
            cin>>w[i];
        }
        for(int i =1;i <= a;i++)
        {
            for(int j = size;j >= w[i];j--)
            {
                dp[j] = max(dp[j],dp[j-w[i]] + v[i]);
            }
        }
        cout<<dp[size]<<endl;
    }
    return 0;
}

http://www.niftyadmin.cn/n/3142475.html

相关文章

用python算圆周率及进度条提示

&#xff08;一&#xff09;圆周率 &#xff1a; &#xff08;1&#xff09;圆周率是指平面上圆的周长与直径之比 &#xff08;ratio of the circumference of a circle to the diameter&#xff09; 。用符号π表示。中国古代有圆率、圆率、周等名称。 &#xff08;2&#xf…

【Kubernetes】kube-dns 持续重启

kuberbetes部署和启动正常&#xff0c;但是kube-dns持续重启 使用命令 kubectl get pods --all-namespaces 得到结果 从图中可以看出kube-dns-c7d85897f-jmntw 在不断重启 使用命令 kubectl describe pod kube-dns-c7d85897f-jmntw -n kube-system 得到结果 Name: ku…

BJTU1820 懒羊羊的作业

BJTU1820 懒羊羊的作业 题目&#xff1a; 看过国产动画片的同学都知道&#xff0c;懒羊羊是一只非常懒的羊&#xff0c;整天除了吃就是睡&#xff0c;根本没有时间做作业。明天就是周一了&#xff0c;村长慢羊羊留的作业&#xff1a; 把 &#x1d45b; n 个整数从大到小排序…

计算分段函数

1、计算f(x)的值&#xff1a;输入x&#xff0c;计算并输出下列分段函数f(x)的值&#xff08;保留1位小数&#xff09;。试编写相应程序。 Yf(x)1/x (当x!0) Yf(x)0 (当x0) #include<stdio.h> int main(void){ float x,y; printf("Enter x:\n"); scanf("%f…

dataframe初始化

转载于:https://www.cnblogs.com/bafenqingnian/p/9152547.html

洛谷题解: P1130 红牌

洛谷题解&#xff1a; P1130 红牌 题目描述 某地临时居民想获得长期居住权就必须申请拿到红牌。获得红牌的过程是相当复杂 &#xff0c;一共包括NNN个步骤。每一步骤都由政府的某个工作人员负责检查你所提交的材料是否符合条件。为了加快进程&#xff0c;每一步政府都派了MMM…

等差素数数列-蓝桥杯

等差素数列 2,3,5,7,11,13,....是素数序列。 类似&#xff1a;7,37,67,97,127,157 这样完全由素数组成的等差数列&#xff0c;叫等差素数数列。 上边的数列公差为 30&#xff0c;长度为 6。 2004 年&#xff0c;格林与华人陶哲轩合作证明了&#xff1a;存在任意长度的素数等差数…

洛谷题解:P1007 独木桥

洛谷题解&#xff1a;P1007 独木桥 题目背景&#xff1a; 战争已经进入到紧要时间。你是运输小队长&#xff0c;正在率领运输部队向前线运送物资。运输任务像做题一样的无聊。你希望找些刺激&#xff0c;于是命令你的士兵们到前方的一座独木桥上欣赏风景&#xff0c;而你留在…