이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |