Total Score Inflation

Topic background

The more students score in our USACO the race, the more we are happy.

We try to design our contests so that people can score as many points as possible, which requires your help

Title Description

We can choose from several types of title race, one where "species" refers to a collection of 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, how many topics should be selected from each category, making the total time 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 the training camp will have a long game) and N, the number of "species" of 1 <= N <= 10,000. Each row comprises two integers later to describe a "genre":

The first solution described integer fraction of this topic can be obtained (1 <= points <= 10000), described the second integer time required to solve this subject (1 <= minutes <= 10000).

Your program should determine how much road we should select topics from each "kind" makes it possible to get the maximum score in a race against time.

Any number of topics from the "type" may be any non-negative number (0 or more).

Calculate the maximum score possible get.

Input and output formats

Input formats:

Line 1: M, the number of "type" of the time and subject N-- race.

Of 2-N + 1 rows: two integers: each "type" topic scores and time consuming.

Output formats:

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

Sample input and output

Input Sample # 1: 
300 4
100 60
250 120
120 100
35 20
Output Sample # 1: 
605

Explanation

Title Translation from NOCOW.

USACO Training Section 3.1

 

analysis:

 This question is obviously backpack DP template title, just to set up the backpack DP template can be.

CODE:

 

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 const int M=10005;
 8 int m,n;
 9 int s[M],t[M],f[M];
10 inline int get(){
11     char c=getchar();
12     int res=0;
13     while (c<'0'||c>'9') c=getchar();
14     while (c>='0'&&c<='9'){
15         res=(res<<3)+(res<<1)+c-'0';
16         c=getchar();
17     }
18     return res;
19 }
20 int main(){
21     m=get(),n=get();
22     for(int i=1;i<=n;i++) s[i]=get(),t[i]=get();
23     for(int i=1;i<=n;i++)
24       for(int j=t[i];j<=m;j++)
25         f[j]=max(f[j],f[j-t[i]]+s[i]);        
26     printf("%d\n",f[m]);
27     //system("pause");
28     return 0;
29 }

 

 

 

 

Guess you like

Origin www.cnblogs.com/kanchuang/p/11150223.html