长安大学第三届ACM-ICPC程序设计竞赛(同步赛)H-Transfer Window

链接: https://www.nowcoder.com/acm/contest/102/H
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述

As the end of the 2017/18 campaign approaches, football clubs across Europe will be assessing theirs quads and deciding which areas they need to improve when the summer transfer window opens. Clubs could sell and buy players as they want.
Aguin is a fan of Real Madrid, and he pays close attention to the summer transfer window.
Among the data he collected, Real Madrid only has P dollars for the transfer window with the financial pressure. Real Madrid has n players, each of them has the ability value a i and the transfer value b i. (Real Madrid can obtain b idollars by selling the i tℎ player).
Also there are m players of other clubs are in the sale, each of them has the ability value c i and the transfer value d i. (Real Madrid will cost d i dollars by buying the i th player)
Aguin is curious the maximum sum of players’ ability value Real Madrid could has. But he’s too stupid to calculate it. Can you tell him?
Pay attention, what  Aguin want is the maximum sum, even the number of Real Madrid players is less than 11.

输入描述:

The first line contains an integer number T, the number of test cases.
For each test case :
The first line contains an integer n(1 ≤ n ≤ 1000), the number of players of Real Madrid.
The following n lines, each contains two integers ai(1 ≤ ai≤ 1000),bi(1 ≤ bi≤ 1000), the ability value
and the transfer value of the ith player of Real Madrid.
The next line contains an integer m(1 ≤ m ≤ 1000), the number of players in the sale.
The following m lines, each contains two integers ci(1 ≤ ci≤ 1000),di(1 ≤ di≤ 1000), the ability value and the transfer value of the itℎ player in the sale.
The next line contains an integer P(1 ≤ P ≤ 1000), the money Real Madrid has at the beginning.
It’s guaranteed that the sum of bi is no more than 1000.

输出描述:

For each test case print the minimum sum of players’ ability value Real Madrid could has.

01背包裸题只要对你所持有的钱先进行预处理,然后套01背包

#include<bits/stdc++.h>
using namespace std;

int dp[20005];
int v[2005];
int p[2005];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        int n;
        scanf("%d",&n);
        int sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&v[i],&p[i]);
            sum=sum+p[i];
        }
        int m,money;
        scanf("%d",&m);
        for(int i=n;i<n+m;i++)
        {
            scanf("%d%d",&v[i],&p[i]);
        }
        scanf("%d",&money);
        money=sum+money;
        //printf("%d\n",money);
        for(int i=0;i<n+m;i++)
        for(int j=money;j>=p[i];j--)
        {
            dp[j]=max(dp[j],dp[j-p[i]]+v[i]);
         //   printf("%d\n",dp[j]);
        }
        printf("%d\n",dp[money]);

    }
    return 0;
}
/*
输入

2
2
92 77
22 22
2
87 29
46 50 
10 
1
1 1
5
92 77
22 23
87 29
46 50 
90 99
100
输出

179
134
*/


猜你喜欢

转载自blog.csdn.net/AC_Meiko/article/details/79948231