This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
// int dp[2001][100001];
map<pair<int,pair<int,int>>,int>dp;
int f(int n, int s, vector<int> &val, vector<int> &w, vector<int> &freq)
{
if (s == 0)
return 0;
if (n == 0)
return 0;
if(dp.find({s,{n,freq[n-1]}})!=dp.end())return dp[{s,{n,freq[n-1]}}];
int ans = 0;
if (w[n - 1] <= s and freq[n - 1] > 0)
{
vector<int> temp = freq;
temp[n - 1]--;
ans = max(ans, val[n - 1] + f(n, s - w[n - 1], val, w, temp));
ans = max(ans, f(n - 1, s, val, w, freq));
}
else
{
ans = max(ans, f(n - 1, s, val, w, freq));
}
return dp[{s,{n,freq[n-1]}}] = ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// memset(dp, -1, sizeof dp);
dp.clear();
int s, n;
cin >> s >> n;
vector<int> val(n), w(n), freq(n);
for (int i = 0; i < n; i++)
{
cin >> val[i] >> w[i] >> freq[i];
}
cout << f(n, s, val, w, freq);
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... |