제출 #438592

#제출 시각아이디문제언어결과실행 시간메모리
438592HaidaraKnapsack (NOI18_knapsack)C++17
73 / 100
1100 ms42612 KiB
    /* * * * * * * * * *
     *   ID: Haidara   *
     *   LANG: C++17   *
     *   PROB:         *
     * * * * * * * * * */
    #include<bits/stdc++.h>
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define FOR(i,n) rep(i,0,n)
    #define per(i,x,n) for(int i=x;i>n;i--)
    #define ROF(i,x) for(int i=x;i>=0;i--)
    #define v(i) vector< i >
    #define p(i,j) pair< i , j >
    #define pii pair<int,int>
    #define m(i,j) map< i , j >
    #define pq(i) priority_queue< i >
    #define ff first
    #define all(x) x.begin(),x.end()
    #define ss second
    #define pp push_back
    using namespace std;
    const int maxn=100002;
    int s,n,v[maxn],w[maxn],k[maxn],dp[maxn][2002];
    int solve(int inx=0,int curr=0)
    {
        if(dp[inx][curr])
            return dp[inx][curr];
        if(inx==n)
            return 0;
        FOR(i,k[inx]+1)
        {
            if(curr+i*w[inx]<=s)
                dp[inx][curr]=max(dp[inx][curr],solve(inx+1,curr+i*w[inx])+i*v[inx]);
            else
                break;
        }
        return dp[inx][curr];
    }
    signed main()
    {
        cin>>s>>n;
        FOR(i,n)
        {
            cin>>v[i]>>w[i]>>k[i];
            k[i]=min(k[i],s/max(1,w[i]-1));
        }
        cout<<solve();
    }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...