이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stack>
#include <iterator>
#include <numeric>
#include <unordered_map>
#include <cstdlib>
#include <ctime>
#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define fdto(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define ull unsigned long long
#define oo 1000000007
#define oooo 1000000000000000007
#define BLOCK 447
#define LOG 19
#define endl "\n"
#define iii pair<ii, int>
#define getbit(x, i) ((x >> i) & 1)
#define TIME cerr << "time: " << (float)clock() / CLOCKS_PER_SEC << " secs \n"
#define maxN 100005
using namespace std;
int s, n;
int v[maxN], w[maxN], k[maxN];
ll f[maxN][2005];
ll dp (int pos, int we){
if (pos == 0 || we == 0) return 0;
if (f[pos][we] != -1) return f[pos][we];
ll res = 0;
fto(i, 0, k[pos]) if (w[pos]*i <= we) res = max(res, dp(pos-1, we - w[pos]*i) + i*v[pos]); else break;
return f[pos][we] = res;
}
void solve(){
cin >> s >> n;
fto(i, 1, n) cin >> v[i] >> w[i] >> k[i];
fto(i, 1, n) fto(j, 0, s) f[i][j] = -1;
cout << dp(n, s) << endl;
}
int main() {
srand(time(NULL));
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t = 1;
// cin >> t;
while(t--){
solve();
}
TIME;
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... |