이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
#define int unsigned long long
int dp[(int)1e5 + 100][(int)2e3 + 10];
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int s,n;cin >> s >> n;
int ll = ceil(log2(s));
vector<array<int,3>> items(n);
for(int i = 0;i<n;i++){
for(int j = 0;j<3;j++)cin >> items[i][j];
}
for(int i =0;i<n;i++){
for(int j = 0;j<=s;j++)
dp[i + 1][j] = dp[i][j];
items[i][2] = min(items[i][2], ((int)1 << ll));;
while(items[i][2] > 0){
int lg = log2(items[i][2]);
items[i][2] -= (1ll << lg);
for(int mask = 0;mask<=lg;mask++){
for(int j= 1;j<=s;j++){
dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - 1]);
int weight = items[i][1]*((int)1 << mask);
int price = items[i][0]*((int)1 << mask);
if(j >= weight)
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight] + price);
}
}
for(int j = 1;j<=s;j++)
dp[i][j] = dp[i + 1][j];
}
}
cout << dp[n][s] << "\n";
}
# | 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... |