码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-2.3-money-pass

时间:2014-09-06 01:02:22      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   问题   

呵呵,这又是一个动态规划问题,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!

 

usaco-2.3-money-pass

标签:style   blog   color   os   io   ar   for   div   问题   

原文地址:http://www.cnblogs.com/dpblue/p/3958903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!