이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
/*--------------------------------------------------------------------------------------------------------------------------*/
int solvee(int i,int cap,int n,vector<vector<int>> &dp,vector<vector<int>> &v){
if(i>=n)return 0;
if(dp[i][cap]!=-1)return dp[i][cap];
int nottake=solvee(i+1,cap,n,dp,v);
int take=0;
for(int k=1;k<=cap;k++){
if(k*v[i][1]<=cap)take=k*v[i][0]+solvee(i+1,cap-k*v[i][1],n,dp,v);
}
return dp[i][cap]=max(take,nottake);
}
void solve() {
int s,n;
cin >> s >> n;
vector<vector<int>> v(n);
for(int i=0;i<n;i++){
int x,y,z;
cin >> x >> y >> z;
v[i]={x,y,z};
}
vector<vector<int>> dp(n,vector<int> (s+1,-1));
cout<<solvee(0,s,n,dp,v)<<endl;
}
int32_t main() {
fastio();
int t=1;
//cin >>t;
while(t--){
solve();
}
}
# | 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... |