zoukankan      html  css  js  c++  java
  • usaco-2.3-money-pass

    呵呵,这又是一个动态规划问题,d(j)=d(j-vv[i])+d(j)

    /*
    ID: qq104801
    LANG: C++
    TASK: money
    */
    
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    int N,V;
    vector<int> vv;
    long long d[10001];
    
    void test()
    {    
        freopen("money.in","r",stdin);
        freopen("money.out","w",stdout);
        cin>>V>>N;
        int t;
        
        for(int i=0;i<V;i++)
        {
            cin>>t;
            vv.push_back(t);
        }
        d[0]=1;
        for(int i=0;i<V;i++)
            for(int j=vv[i];j<=N;j++)
                if (j>=vv[i]) d[j]=d[j-vv[i]]+d[j];
        cout<<d[N]<<endl;
        
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USER: cn tom [qq104801]
    TASK: money
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.008 secs, 3584 KB]
       Test 2: TEST OK [0.003 secs, 3584 KB]
       Test 3: TEST OK [0.003 secs, 3584 KB]
       Test 4: TEST OK [0.003 secs, 3584 KB]
       Test 5: TEST OK [0.003 secs, 3584 KB]
       Test 6: TEST OK [0.005 secs, 3584 KB]
       Test 7: TEST OK [0.008 secs, 3584 KB]
       Test 8: TEST OK [0.005 secs, 3584 KB]
       Test 9: TEST OK [0.005 secs, 3584 KB]
       Test 10: TEST OK [0.005 secs, 3584 KB]
       Test 11: TEST OK [0.005 secs, 3584 KB]
       Test 12: TEST OK [0.008 secs, 3584 KB]
       Test 13: TEST OK [0.011 secs, 3584 KB]
    
    All tests OK.
    
    YOUR PROGRAM ('money') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
    
    Here are the test data inputs:
    
    ------- test 1 ----
    1 1
    1
    ------- test 2 ----
    3 10
    1 2 5
    ------- test 3 ----
    10 100
    1 2 3 4 5 6 7 8 9 10
    ------- test 4 ----
    25 1000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25
    ------- test 5 ----
    25 9999
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    25000
    26
    ------- test 6 ----
    25 9999
    346
    130
    982
    1090
    1656
    7117
    7595
    6415
    2948
    1126
    9004
    4558
    3571
    2879
    8492
    1360
    5412
    6721
    2463
    5047
    7119
    1441
    7190
    3985
    1214
    ------- test 7 ----
    25 999
    7843
    4639
    1653
    3876
    5457
    2152
    2524
    2412
    7461
    3564
    4634
    7717
    5947
    4056
    1048
    6123
    1757
    5964
    1137
    3094
    671
    5869
    2719
    631
    3563
    ------- test 8 ----
    25 100
    25
    24
    23
    22
    21
    20
    19
    18
    17
    16
    15
    14
    13
    12
    11
    10
    9
    8
    7
    6
    5
    4
    3
    2
    1
    ------- test 9 ----
    25 100
    37
    36
    35
    34
    33
    32
    31
    30
    29
    28
    27
    26
    25
    24
    23
    22
    21
    20
    19
    18
    17
    16
    15
    14
    13
    ------- test 10 ----
    5 10000
    5 8 13 21 34
    ------- test 11 ----
    17 500
    11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    ------- test 12 ----
    8 10000
    1 2 3 4 5 6 20 25
    ------- test 13 ----
    17 2000
    11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

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

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

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

    你会知其所以然,呵呵。

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

  • 相关阅读:
    Google Optimize 安装使用教程
    PostgreSQL drop database 显示会话没有关闭 [已解决]
    c#之线程同步--轻量级同步 Interlocked
    CentOS7 'Username' is not in the sudoers file. This incident will be reported
    Mac 如何删除应用、软件
    Oracle的存储过程基本写法
    我的一个PLSQL【我】 循环嵌套、游标使用、变量定义、查询插入表、批量提交事务、字符串截取、动态sql拼接执行
    Oracle定义常量和变量
    ORACLE中%TYPE和%ROWTYPE的使用
    pls_integer类型
  • 原文地址:https://www.cnblogs.com/dpblue/p/3958903.html
Copyright © 2011-2022 走看看