Submission #987117

#TimeUsernameProblemLanguageResultExecution timeMemory
987117vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
102 ms4048 KiB
#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]); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...