[Usaco2009 Feb]Stock Market 股票市场 完全背包

Code:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<stack>
#include<string>
using namespace std;
void setIO(string a){ freopen((a+".in").c_str(),"r",stdin),freopen((a+".out").c_str(),"w",stdout); }
void shutIO(){fclose(stdin),fclose(stdout);}
 
#define maxn 500090
#define inf 100000000
int val[200][200], f[maxn];
int main(){
    int S,D,M;
    scanf("%d%d%d",&S,&D,&M);
    for(int i=1;i<=S;++i)
        for(int j=1;j<=D;++j) scanf("%d",&val[j][i]);
    for(int i=2;i<=D;++i){
        int tmp=0;
        memset(f,0,sizeof(f));
        for(int j=1;j<=S;++j){
            int cost=val[i-1][j],v=val[i][j];
            for(int k=cost;k<=M;++k) f[k]=max(f[k],f[k-cost]+v-cost),tmp=max(tmp,f[k]);
        }
        M+=tmp;
    }
    printf("%d\n",M);
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/guangheli/p/9928985.html