1 solutions

  • 0
    @ 2024-12-5 18:10:16

    C++ :

    #include<bits/stdc++.h>
    #define up(l,r,i) for(int i=l;i<=r;i++)
    #define dn(l,r,i) for(int i=l;i>=r;i--)
    using namespace std;
    
    typedef long long LL;
    const int INF =2147483647;
    int qread(){
        int w=1,c,ret;
        while((c=getchar())> '9'||c< '0')
        w=(c=='-'?-1:1); ret=c-'0';
        while((c=getchar())>='0'&&c<='9')
        ret=ret*10+c-'0';
        return ret*w;
    }
    const int MAXN =100+3,MAXM=1e3+3,MAXP=1e4+3;
    int t,n,m,P[MAXM],Q[MAXM],C[MAXM],lst[MAXM];
    int dp[MAXP],res;
    int main(){
        t=qread(),n=qread(),res=m=qread();
        up(1,n,i) lst[i]=qread();
        up(1,m,i) dp[i]=i;
        up(2,t,i){
            up(1,n,j) P[j]=qread(),C[j]=lst[j];
            up(1,res,i) dp[i]=i;
            up(1,n,j) up(1,res,k){
                if(k>=C[j]) dp[k]=max(dp[k],dp[k-C[j]]+P[j]);
            }
            res=dp[res];
            memcpy(lst,P,sizeof(lst));
        }
        printf("%d\n",res);
        return 0;
    }
    
    • 1

    Information

    ID
    9120
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By