USACO Score Inflation

Luo Gu P2722 Total Score Inflation

https://www.luogu.org/problem/P2722

JDOJ 1697: Score Inflation

https://neooj.com/oldoj/problem.php?id=1697

Description

The more students score in our Chittagong High School (USACO) competition in the happier we are. We try to design our contests so that people can score as many points as possible, we need your help. We can choose from several competition categories the problem, here's a "species" refers to a collection of a contest topic, to solve a set of topics that require the same amount of time and energy to get the same score.
your task is to write a program to tell USACO staff, it should be from each how many questions to select a category, so that the total time-consuming to solve the problem of competition in the prescribed time and score maximum.
inputs include race against time, M (1 <= M < = 10,000) ( Do not worry, you go to training camp there will in the long match) and N, the number of "type" of 1 <= N <= 10,000.
each line comprises two integers later to describe a "genre":
the first integer instructions to address this topic You can get scores (1 <= points <= 10000 ), the second integer instructions for resolving the time required for this topic (1 <= minutes <= 10000 ).
your program should determine we should be selected from each "kind" how much time can make road title in the competition The maximum score obtained.
The maximum number of points from any of the subject "genre" may be any non-negative number (0 or more). The resulting calculated possible.

Input

Line 1: M, the number of "type" of the time and subject N-- race.  
Of 2-N + 1 rows: two integers: Processed fractions and each "type" topic.

Output

A single line that includes the biggest score in a given limit may get.

Sample Input

300 4 100 60 250 120 120 100 35 20

Sample Output

605

HINT

 

From 4 "species" selected the first two "species" selected two title three questions

 
Intense love for his alma mater, so I resolutely abandoned the normal problems surface, select the surface JDOJ the title.
In fact, this is a backpack full of template questions for newcomers to practice hand, to deepen understanding of the full backpack.
 
The so-called full backpack, there is n categories, each of which does not limit the number, the process of seeking final 01 backpack ...
Therefore, we also used much the same way with 01 backpack
DP [i] [j] denotes the i-th former items can be filled to the maximum capacity of j on the backpack.
So as the state transition equation and the 01 backpack.
But as long as greater than 5000 * 5000, this question will be ringing off the hook, so we need to get moving owned a one-dimensional array.
One-dimensional dynamic normalization may be more difficult to do, but just two-dimensional and essentially the same.
I do that dimension, as long as dp [j] represents the maximum fill capacity value of j backpack.
So dynamic transfer equation is completely backpack template, it came out:
dp[i]=max(dp[i],dp[i-w[i]]+v[i]);
 
Here is the code for this question:
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
int a[10001],b[10001],dp[10001];
int main()
{
    scanf("%d%d",&m,&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]);
    for(int i=1;i<=n;i++)
        for(int j=b[i];j<=m;j++)
            dp[j]=max(dp[j],dp[j-b[i]]+a[i]);
    printf("%d",dp[m]);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/fusiwei/p/11242731.html
Recommended