이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[2005][2005];
int search(int i, int remW, vector<pair<int,int>>& kp, int total){
if (i == total) return 0;
if (remW == 0) return 0;
if (dp[i][remW] != -1) return dp[i][remW];
if (kp[i].first <= remW){
return dp[i][remW] = max(search(i+1,remW,kp,total),search(i+1,remW-kp[i].first,kp,total)+kp[i].second);
}
else{
return dp[i][remW] = search(i+1,remW,kp,total);
}
}
signed main() {
memset(dp,-1,sizeof(dp));
int s,n;
cin >> s >> n;
vector<int> arr[2000];//offset weight by one for now
for (int i = 0; i<n; i++){
int v,w,k;
cin >> v >> w >> k;
k = min(2000LL,k);
w--;
int sz1 = arr[w].size();
int left = min(2000-sz1,k);
for (int j = 0; j<left; j++){
arr[w].push_back(v);
}
}
int total = 0;
vector<pair<int,int>> kp;
for (int i = 0; i<2000; i++){
int sz = arr[i].size();
total += sz;
for (int j = 0; j<sz; j++){
kp.push_back({i+1,arr[i][j]}); //weight,value
}
}
cout << search(0,s,kp,total) << '\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... |