zoukankan      html  css  js  c++  java
  • USACO Section 3.1 Score Inflation (inflate)

    Score Inflation

    The more points students score in our contests, the happier we here at the USACO are. We try to design our contests so that people can score as many points as possible, and would like your assistance.

    We have several categories from which problems can be chosen, where a "category" is an unlimited set of contest problems which all require the same amount of time to solve and deserve the same number of points for a correct solution. Your task is write a program which tells the USACO staff how many problems from each category to include in a contest so as to maximize the total number of points in the chosen problems while keeping the total solution time within the length of the contest.

    The input includes the length of the contest, M (1 <= M <= 10,000) (don't worry, you won't have to compete in the longer contests until training camp) and N, the number of problem categories, where 1 <= N <= 10,000.

    Each of the subsequent N lines contains two integers describing a category: the first integer tells the number of points a problem from that category is worth (1 <= points <= 10000); the second tells the number of minutes a problem from that category takes to solve (1 <= minutes <= 10000).

    Your program should determine the number of problems we should take from each category to make the highest-scoring contest solvable within the length of the contest. Remember, the number from any category can be any nonnegative integer (0, one, or many). Calculate the maximum number of possible points.

    PROGRAM NAME: inflate

    INPUT FORMAT

    Line 1: M, N -- contest minutes and number of problem classes
    Lines 2-N+1: Two integers: the points and minutes for each class

    SAMPLE INPUT (file inflate.in)

    300 4
    100 60
    250 120
    120 100
    35 20
    

    OUTPUT FORMAT

    A single line with the maximum number of points possible given the constraints.

    SAMPLE OUTPUT (file inflate.out)

    605
    

    (Take two problems from #2 and three from #4.)

    思路:看着这个数据,总觉得要T(如果数据变态的话),做了一个小小的优化~

    Executing...
       Test 1: TEST OK [0.000 secs, 3340 KB]
       Test 2: TEST OK [0.000 secs, 3340 KB]
       Test 3: TEST OK [0.000 secs, 3340 KB]
       Test 4: TEST OK [0.000 secs, 3340 KB]
       Test 5: TEST OK [0.000 secs, 3340 KB]
       Test 6: TEST OK [0.011 secs, 3340 KB]
       Test 7: TEST OK [0.032 secs, 3340 KB]
       Test 8: TEST OK [0.108 secs, 3340 KB]
       Test 9: TEST OK [0.184 secs, 3340 KB]
       Test 10: TEST OK [0.184 secs, 3340 KB]
       Test 11: TEST OK [0.000 secs, 3340 KB]
       Test 12: TEST OK [0.000 secs, 3340 KB]
    
    All tests OK.

     1 /*
     2 ID:wuhuaju2
     3 PROG:inflate
     4 LANG:C++
     5 */
     6 
     7 #include <cstdio>
     8 #include <iostream>
     9 #include <cstdlib>
    10 #include <algorithm>
    11 #include <cstring>
    12 using namespace std;
    13 
    14 const int maxn=10010,maxt=10010;
    15 int t[maxn],f[maxt],v[maxn];
    16 int x,y,ti,n;
    17 
    18 void close()
    19 {
    20     fclose(stdin);
    21     fclose(stdout);
    22     exit(0);
    23 }
    24 
    25 void work()
    26 {
    27 }
    28 
    29 void init ()
    30 {
    31 freopen("inflate.in","r",stdin);
    32 freopen("inflate.out","w",stdout);
    33 memset(f,0,sizeof(f));
    34 x=0;
    35 y=10000000;
    36    scanf("%d %d",&ti,&n);
    37     for (int i=1;i<=n;i++)
    38         scanf("%d %d",&v[i],&t[i]);
    39     for (int i=1;i<=n;i++)
    40     {
    41         if ( (t[i]<x) && v[i]<y ) continue;
    42         for (int j=t[i];j<=ti;j++)
    43             f[j]=max(f[j],f[j-t[i]]+v[i]);
    44         if ( t[i]>x && v[i]>y) 
    45         {
    46             x=t[i]; y=v[i];
    47         }
    48     }
    49     cout<<f[ti]<<endl;
    50 }
    51 
    52 int main ()
    53 {
    54     init();
    55     work();
    56     close();
    57     return 0;
    58 }
    
    
    
     
  • 相关阅读:
    二进制安全的一些基础知识
    栈溢出笔记-第五天
    一次基于白盒的渗透测试
    栈溢出笔记-第四天
    Hadoop1-认识Hadoop大数据处理架构
    Kubernetes1-K8s的简单介绍
    Docker1 架构原理及简单使用
    了解使用wireshark抓包工具
    Linux系统设置开机自动运行脚本的方法
    Mariadb/Mysql 主主复制架构
  • 原文地址:https://www.cnblogs.com/cssystem/p/2901650.html
Copyright © 2011-2022 走看看