考前复习(codevs 2837)

2837 考前复习

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 
 
题目描述 Description

Aiden马上要考试了,可他还没怎么复习,于是他决定临时抱佛脚。他列了N个知识点,并分析出了复习每个知识点所需的时间t以及可能获得的分数k。他现在还有T时间来复习,他希望选择正确的知识点来在最短的时间内获得最高的期望分数。

输入描述 Input Description

第一行,两个数,分别为N、T。

接下来的N行,每行两个数t、k,表示一个知识点所需的时间和期望得分。

输出描述 Output Description

一行,一个数,表示可以获得的最高期望得分。

样例输入 Sample Input

3 5

3 5

3 2

2 2

样例输出 Sample Output

7

#include<cstdio>
#include<iostream>
#define M 10010
#define N 5010
using namespace std;
int f[M],v[N],w[N];
int main()
{
    int m,n;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
      scanf("%d%d",&w[i],&v[i]);
    for(int i=1;i<=n;i++)
      for(int j=m;j>=w[i];j--)
        f[j]=max(f[j],f[j-w[i]]+v[i]);
    printf("%d",f[m]);
    return 0;
}
View Code

 

posted @ 2016-06-25 17:00  karles~  阅读(120)  评论(0编辑  收藏  举报