제출 #490651

#제출 시각아이디문제언어결과실행 시간메모리
490651CyberSleeperKnapsack (NOI18_knapsack)C++14
29 / 100
1 ms332 KiB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ld          long double
#define pii         pair<ll, ll>
#define pll         pair<ll, ll>
#define ar3         array<ll, 3>
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
using namespace std;

const ll MX=100005, MOD=1e9+7, BLOCK=500, INF=2e9+7;
const ll INFF=1e18+7;
const ld ERR=1e-7, pi=3.14159265358979323846;

ll S, N, V[MX], W[MX], K[MX], DP[2][2005], cnt[2005];

int main(){
    fastio;
    cin >> S >> N;
    for(ll i=1; i<=N; i++){
        cin >> V[i] >> W[i] >> K[i];
    }
    for(ll i=1; i<=S; i++)
        DP[0][i]=-INF;
    DP[0][0]=0;
    for(ll i=1; i<=N; i++){
        ll now=i%2, bef=now^1;
        for(ll j=0; j<=S; j++){
            DP[now][j]=DP[bef][j];
            cnt[j]=0;
            if(j>=W[i]){
                DP[now][j]=max(DP[now][j], DP[bef][j-W[i]]+V[i]);
                cnt[j]=1;
                if(cnt[j-W[i]]<K[i]){
                    DP[now][j]=max(DP[now][j], DP[now][j-W[i]]+V[i]);
                    cnt[j]=cnt[j-W[i]]+1;
                }
            }
        }
    }
    N%=2;
    for(ll i=0; i<S; i++)
        DP[N][S]=max(DP[N][S], DP[N][i]);
    cout << DP[N][S] << nl;
}
#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...