zoukankan      html  css  js  c++  java
  • codevs——T3111 CYD啃骨头

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

    CYD吃饭时有N个骨头可以啃,但CYD要午睡了,所以他只有M分钟吃饭,已知啃每个骨头需花费时间Ai,可以得到Bi个单位的营养。问CYD最多得到多少营养。

    输入描述 Input Description

    M  N

    A1 B1

    A2 B2

    ……

    AN BN

    输出描述 Output Description

    得到的最大营养值

    样例输入 Sample Input

    10  3

    5  20

    3  15

    8  29

    样例输出 Sample Output

    35

    数据范围及提示 Data Size & Hint

     对于100%的数据  N≤100  M≤1000  Ai,Bi≤100

     1 #include <algorithm>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 
     6 int n,m;
     7 int t[105],val[105];
     8 int f[10015];
     9 
    10 int main()
    11 {
    12     scanf("%d%d",&m,&n);
    13     for(int i=1;i<=n;i++)
    14         scanf("%d%d",&t[i],&val[i]);
    15     for(int i=1;i<=n;i++)
    16         for(int j=m;j>=t[i];j--)
    17         f[j]=max(f[j],f[j-t[i]]+val[i]);
    18     printf("%d",f[m]);
    19     return 0;
    20 }
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    php中的form表单
    http
    PHP做的简单计算器
    用Js写贪吃蛇
    ajax简单操作,验证用户名是否可以
    关于ARM PC值
    阅读脚本控制pwm代码
    编译选项
    关于机器码、原码、反码、补码
    makefile学习之函数
  • 原文地址:https://www.cnblogs.com/Shy-key/p/6735833.html
Copyright © 2011-2022 走看看