이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 1000000007;
ll power(ll base, ll n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(ll n){
return power(n, MOD-2);
}
ll add(ll a, ll b){
return (a+b) % MOD;
}
ll mul(ll a, ll b){
return (a*b) % MOD;
}
ll gcd(ll a, ll b){
if (a == 0) return b;
if (a == 1) return 1;
return gcd(b % a, a);
}
int main(){
ios::sync_with_stdio(false);
int s, n; cin >> s >> n;
vi cnt(s+1);
vector<pair<int, ii> > knap;
FOR(i, 0, n){
int v, w, k; cin >> v >> w >> k;
if (w > s) continue;
knap.pb({v, {w, k}});
}
sort(knap.rbegin(), knap.rend());
n = knap.size();
vi V[s+1];
FOR(i,1,s+1) V[i].pb(0);
FOR(i, 0, n){
int v = knap[i].F, w = knap[i].S.F, k = knap[i].S.S;
int len = V[w].size();
if (len >= s/w+1) continue;
FOR(j, len, min(len+k, s/w+1)){
V[w].pb(V[w][j-1] + v);
}
}
int dp[s+1][s+1];
ms(dp, 0, sizeof(dp));
FOR(i, 1, s+1){
FOR(j, 0, s+1){
FOR(k, 0, min(j/i+1, (int)V[i].size())){
dp[i][j] = max(dp[i][j], dp[i-1][j-k*i] + V[i][k]);
}
}
}
cout << dp[s][s] << '\n';
return 0;
}
# | 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... |