zoukankan      html  css  js  c++  java
  • usaco-3.1-stamps-pass

    呵呵,这个想了半天,参考了一下网上,提交了这个方案:

    /*
    ID: qq104801
    LANG: C++
    TASK: stamps
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <map>
    #include <list>
    #include <set>
    #include <queue>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    
    #define INF 9999999
    
    int k,n;
    int v[101];
    int f[2000001]={0};
    
    
    void test()
    {    
        freopen("stamps.in","r",stdin);
        freopen("stamps.out","w",stdout);
        scanf("%d %d",&k,&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&v[i]);
    
        int min;
        int i=1;
        while(true)
        {
            min=INF;
            for(int j=1;j<=n;j++)
                if((i-v[j])>=0 && (f[i-v[j]]+1<min))
                    min=f[i-v[j]]+1;
            if(min>k)break;
            f[i]=min;
            ++i;
        }
        cout<<i-1<<endl; 
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USACO Training
    Grader Results     
    4 users online
    CHN/2 DNK/1 USA/1
    
    USER: cn tom [qq104801]
    TASK: stamps
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.005 secs, 11184 KB]
       Test 2: TEST OK [0.003 secs, 11184 KB]
       Test 3: TEST OK [0.005 secs, 11184 KB]
       Test 4: TEST OK [0.005 secs, 11184 KB]
       Test 5: TEST OK [0.003 secs, 11184 KB]
       Test 6: TEST OK [0.003 secs, 11184 KB]
       Test 7: TEST OK [0.003 secs, 11184 KB]
       Test 8: TEST OK [0.011 secs, 11184 KB]
       Test 9: TEST OK [0.008 secs, 11184 KB]
       Test 10: TEST OK [0.054 secs, 11184 KB]
       Test 11: TEST OK [0.356 secs, 11184 KB]
       Test 12: TEST OK [0.111 secs, 11184 KB]
       Test 13: TEST OK [0.016 secs, 11184 KB]
    
    All tests OK.
    
    Your program ('stamps') produced all correct answers! This is your submission #2 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    5 2
    1 3
    ------- test 2 ----
    1 4
    1 2 3 5
    ------- test 3 ----
    2 4
    1 2 4 8
    ------- test 4 ----
    4 4
    1 2 4 8
    ------- test 5 ----
    20 1
    1
    ------- test 6 ----
    40 3
    5 1 2
    ------- test 7 ----
    3 10
    29 50 36 43 1 2 4 8 15 22
    ------- test 8 ----
    6 10
    1 2 9 31 255 480 4 15 63 127
    ------- test 9 ----
    8 12
    1 2 4 15 9 31 63 127 255 511 1000 1999
    ------- test 10 ----
    200 14
    1 2 4 15 9 31 63 2100 3500 127 255 511 1000 1999
    ------- test 11 ----
    200 50
    1 37 87 14 137 4016 157 5383 7318 8662 7074 2821 5250 9704 8986
    1375 6587 5962 7190 339 1981 9719 7012 385 7926 5159 3259 5144 7846 8854
    3249 3198 8408 2784 6249 4648 6799 2757 31 4116 7771 3456 3288 3020 3159
    8625 747 9745 938 10000
    ------- test 12 ----
    200 15
    1 3 14 59 265 358 979 323 846 26 433 832 7950 28 841
    ------- test 13 ----
    200 15
    1 1 1 1 1 10 10 10 10 10 100 100 100 100 100
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    jQuery选择器大全
    MVC自定义数据验证(两个时间的比较)
    SQLServer开发总结
    疯狂的订餐系统软件需求分析挑战之旅1
    疯狂的订餐系统软件需求分析挑战之旅2
    net中C#自动化调用Word的实例总结
    软件开发中代码自动化的一点浅见
    代码自动化(1)开篇
    代码自动化(2)程序设计
    Excel 手机号码、身份证 等信息 导入到SQL2005 中,转换成字符是自动变成 科学计数法 的解决方法
  • 原文地址:https://www.cnblogs.com/dpblue/p/3966517.html
Copyright © 2011-2022 走看看