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

usaco-3.1-inflate-pass

呵呵,这个是背包问题:

/*ID: qq104801LANG: C++TASK: inflate*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <list>#include <set>#include <queue>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;#define NMAX 11111int m,n;int minutes[NMAX];int points[NMAX];int dp[NMAX];void debug_dummy(){    return;}void test(){        freopen("inflate.in","r",stdin);    freopen("inflate.out","w",stdout);    cin>>m>>n;    for(int i=1;i<=n;i++)        cin>>points[i]>>minutes[i];    memset(dp,0,sizeof(dp));    for(int i=1;i<=n;i++)        for(int j=minutes[i];j<=m;j++)        {            dp[j]=max(dp[j],dp[j-minutes[i]]+points[i]);            if (dp[j]>0)debug_dummy();        }    cout<<dp[m]<<endl; }int main () {            test();            return 0;}

test data:

USACO TrainingGrader Results     12 users online61.10.110.236/1 CHN/3 DEU/2 IND/2 ROM/1 USA/2 YUG/1USER: cn tom [qq104801]TASK: inflateLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.003 secs, 3500 KB]   Test 2: TEST OK [0.005 secs, 3500 KB]   Test 3: TEST OK [0.008 secs, 3500 KB]   Test 4: TEST OK [0.008 secs, 3500 KB]   Test 5: TEST OK [0.005 secs, 3500 KB]   Test 6: TEST OK [0.014 secs, 3500 KB]   Test 7: TEST OK [0.051 secs, 3500 KB]   Test 8: TEST OK [0.111 secs, 3500 KB]   Test 9: TEST OK [0.200 secs, 3500 KB]   Test 10: TEST OK [0.211 secs, 3500 KB]   Test 11: TEST OK [0.003 secs, 3500 KB]   Test 12: TEST OK [0.003 secs, 3500 KB]All tests OK.YOUR PROGRAM (‘inflate‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----300    4100 60250 120120 10035 20------- test 2 ----10000 110000 1------- test 3 ----1000 2040 11333 3362172 3561958 5379499 7014443 2756983 109416 5658155 1667644 6869596 8284268 2208396 9538109 9246048 4525998 6627201 5504062 1146713 1224911 475------- test 4 ----4000 5040 43333 13412172 14231958 21489499 28024443 11006983 436416 22588155 6617644 27439596 33114268 8788396 38118109 36936048 18055998 26477201 21974062 4566713 4864911 19003445 22572645 34754231 7201637 27806455 215431 24942690 31493866 18455812 15082799 24148052 683.............

 

usaco-3.1-inflate-pass