2020 Winter Holiday [gmoj1593] [GDKOI training] [TV game problem vidgame] [DP]

Title description

Farmer John's cows are addicted to games! Originally, FJ wanted to take them to shock their addiction according to Professor Tao's practice, but later he found that cows produced more milk than the original after playing games. Obviously, this is because the satisfied cow will produce more milk. However, the cows have huge differences on the question of which is the best gaming platform. One cow wants to buy an Xbox 360 to run "Halo 3"; another cow wants a Nintendo Wii to run "Nintendo Star Fighting X"; the third cow wants to play "Diving" on PlayStation 3. "Dragon Shadow 4", by the way, can also watch some high-quality movies.

FJ wants to buy some gaming platforms and some games within a given budget, so that his cows produce the most cows to raise the most children. FJ studied N (1 <= N <= 50) game platforms, the price of each game platform is P_i (1 <= P_i <= 1000), and each game platform has G_i (1 <= G_i < = 10) games that can only be run on this platform. Obviously, cows must first buy a game platform before they can buy games running on this game platform. Each game has a game price GP_j (1 <= GP_j price <= 100) and has an output value PV_j (1 <= PV_j <= 1000000), indicating how much milk a cow will produce after playing this game .

Finally, Farmer John ’s budget is V (1 <= V <= 100000), which is the maximum amount of money he can spend. Please help him determine what game platform and game he should buy, so that he can get the largest sum of output value.

Consider the following data, there are N game platforms, and there is a budget of V = $ 800. The first game platform costs $ 300 and there are two games with prices of $ 30 and $ 25 respectively. Their output values ​​are as follows:

  游戏 #    花费      产出值
 
      1     $30       50
 
      2     $25       80

The second platform is priced at $ 600, and there is only one game:

 游戏 #    花费      产出值
  1          $50       130

The third platform is priced at $ 400, and there are three games:

 游戏 #    花费      产出值
 
      1     $40        70
 
      2     $30        40
 
      3     $35        60

Farmer John should buy platforms 1 and 3, and buy game 2 of platform 1, as well as game 1 and game 3 of platform 3. Make his final output value the largest, 210 output value:

 预算:        $800     
 
    平台 1      -$300
 
        游戏 2  -$25               80
 
    平台 3      -$400
 
        游戏 1   -$40              70
 
        游戏 3   -$35              60
 
  -------------------------------------------
 
    总计:           0 (>= 0)      210

Input

Line 1: Two integers separated by spaces: N and V
Lines 2 to N + 1: Line i + 1 represents the price of the i-th game platform and the games that can be run on this game platform. Contains: P_i, G_i and G_i pairs of integers separated by spaces GP_j, PV_j

Output

Line 1: The largest output value that Farmer John can get within the budget.

Sample input

3 800
300 2 30 50 25 80
600 1 50 130
400 3 40 70 30 40 35 60

Sample output

210

analysis

A deformed 01 backpack. . .
Let f [i] [1] be the current maximum output value of i yuan and f [i] [2] the last maximum output value, we can get the dynamic transfer equation: when no platform is selected: f [ i ] [ 0 ] = f [ i ] [ 1 ] f [i] [0] = f [i−platform cost] [1] When the selected game to be selected from the platform: f [ i ] [ 0 ] = m a x ( f [ i ] [ 0 ] + c , f [ i ] [ 0 ] ) f [i] [0] = max (f [i−game cost] [0] + c, f [i] [0]) last recorded maximum value (play ring): f [ j ] [ 1 ] = m a x ( f [ j ] [ 0 ] , f [ j ] [ 1 ] ) f[j][1]=max(f[j][0],f[j][1])

Code on

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,v,f[100001][3],x,ans,m,p,q;
int main()
{
    freopen("vidgame.in","r",stdin);
    freopen("vidgame.out","w",stdout);
    cin>>n>>v;
    for(int i=1;i<=n;i++)
    {
        cin>>m>>x;
        for(int j=v;j>=m;j--)
        {
        	f[j][1]=f[j-m][2];
		}
        for(int j=1;j<=x;j++)
        {
            cin>>p>>q;
            for(int k=v;k>=m+p;k--)
            {
            	f[k][1]=max(f[k-p][1]+q,f[k][1]);
			}   
        }
        for(int j=1;j<=v;j++)
        {
        	f[j][2]=max(f[j][2],f[j][1]);
		}
    }
    cout<<f[v][2];
}

Published 110 original articles · 100 praises · views 8017

Guess you like

Origin blog.csdn.net/dglyr/article/details/105056511