이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define forn for (int i = 0; i < n; i++)
#define int long long
#define ed "\n"
#define cyes cout << "YES\n"
#define cno cout << "NO\n"
#define pb push_back
#define deb cout << "Hi\n"
#define pint pair<int, int>
const long long MOD = 1000000007;
void dbg_out(){cerr<<"\n";}
template<typename Head,typename... Tail>
void dbg_out(Head H,Tail... T){cerr<<' '<<H;dbg_out(T...);}
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dbg_out(__VA_ARGS__)
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------//
int32_t main(){
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int w, n; cin>>w>>n;
vector<array<int, 3>> v;
forn{
int vi, wi, ki; cin>>vi>>wi>>ki;
v.pb({vi, wi, ki});
}
vector<array<int, 2>> v2;
for(auto val: v){
auto[vi, wi, ki] = val;
for(int i = 0; i <= 34; i++){
int x = (1LL << i);
if(ki < x) break;
ki -= x;
v2.pb({vi*x, wi*x});
}
if(ki > 0) v2.pb({vi*ki, wi*ki});
}
n = v2.size();
int dp[n][w+1];
for(int i = 0; i < n; i++){
for(int j = 0; j <= w; j++) dp[i][j] = 0;
}
for(int i = 0; i < n; i++){
for(int j = 1; j <= w; j++){
if(i == 0){
if(v2[i][1] == j) dp[i][j] = v2[i][0];
}
else{
dp[i][j] = dp[i-1][j];
if(j - v2[i][1] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-v2[i][1]] + v2[i][0]);
}
}
}
// forn{
// for(int j = 0; j <= w; j++) cout << dp[i][j] << " ";
// cout << ed;
// }
int ans = 0;
for(int i = 0; i <= w; i++) ans = max(ans, dp[n-1][i]);
cout << ans << ed;
}
# | 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... |