• 87. 考前复习(动态规划)


    2837 考前复习

     

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

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

    输入描述 Input Description

    第一行,两个数,分别为NT

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

    输出描述 Output Description

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

    样例输入 Sample Input

    5

    5

    2

    2

    样例输出 Sample Output

    7

    数据范围及提示 Data Size & Hint

    对于10%的数据,0100100

    对于50%的数据,01000010000

    对于100%的数据,0500001000001000

    分类标签 Tags 点此展开 

    代码:
    #include
    #include
    using namespace std;
    #define INFt 10001
    #define INFzs 5001
    int f[INFt],tim[INFzs],fs[INFzs],n,t;
    void input()
    {
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;++i)
    scanf("%d%d",&tim[i],&fs[i]);
    }
    int main()
    {
    input();
    for(int i=1;i<=n;++i)
     for(int j=t;j>=1;j--)
     if(j>=tim[i])
     f[j]=max(f[j],f[j-tim[i]]+fs[i]);
    printf("%d ",f[t]);
    return 0;
     
  • 相关阅读:
    hdu 1159 Common Subsequence(最长公共子序列)
    Codeforces Round #313 (Div. 2)
    cf 558A Lala Land and Apple Trees
    zoj 2193 Window Pains
    poj 2031 Building a Space Station(最小生成树)
    zoj 1060 Sorting It All Out(拓扑排序)
    拓扑排序
    poj 1287 Networking
    zoj 1586 QS Network
    poj 1679 The Unique MST
  • 原文地址:https://www.cnblogs.com/c1299401227/p/5370733.html
Copyright © 2020-2023  润新知