首页 > 代码库 > usaco-3.1-stamps-pass

usaco-3.1-stamps-pass

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

/*ID: qq104801LANG: 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 9999999int 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 TrainingGrader Results     4 users onlineCHN/2 DNK/1 USA/1USER: cn tom [qq104801]TASK: stampsLANG: C++Compiling...Compile: OKExecuting...   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 21 3------- test 2 ----1 41 2 3 5------- test 3 ----2 41 2 4 8------- test 4 ----4 41 2 4 8------- test 5 ----20 11------- test 6 ----40 35 1 2------- test 7 ----3 1029 50 36 43 1 2 4 8 15 22------- test 8 ----6 101 2 9 31 255 480 4 15 63 127------- test 9 ----8 121 2 4 15 9 31 63 127 255 511 1000 1999------- test 10 ----200 141 2 4 15 9 31 63 2100 3500 127 255 511 1000 1999------- test 11 ----200 501 37 87 14 137 4016 157 5383 7318 8662 7074 2821 5250 9704 89861375 6587 5962 7190 339 1981 9719 7012 385 7926 5159 3259 5144 7846 88543249 3198 8408 2784 6249 4648 6799 2757 31 4116 7771 3456 3288 3020 31598625 747 9745 938 10000------- test 12 ----200 151 3 14 59 265 358 979 323 846 26 433 832 7950 28 841------- test 13 ----200 151 1 1 1 1 10 10 10 10 10 100 100 100 100 100Keep up the good work!Thanks for your submission!

 

usaco-3.1-stamps-pass