Submission #696849

#TimeUsernameProblemLanguageResultExecution timeMemory
696849phongcdKnapsack (NOI18_knapsack)C++14
0 / 100
2 ms340 KiB
#include <bits/stdc++.h> #define ll long long #define ii pair <int, int> #define ill pair <ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define file "test" using namespace std; const int N = 1e5 + 5; const int MOD = 1e9 + 7; const ll INF = 1e18; const int base = 311; const int BLOCK_SIZE = 2000; int n, m, v[N], w[N], k[N]; ll f[N][2005]; vector <int> decompose(int t) { vector <int> a; int x = 1; while (x < t) { a.push_back(x); t -= x; x *= 2; } a.push_back(t); return a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen(file".inp","r",stdin); freopen(file".out","w",stdout); #endif cin >> m >> n; for (int i = 1; i <= n; i ++) { cin >> v[i] >> w[i] >> k[i]; vector <int> b = decompose(k[i]); for (auto k: b) for (int j = m; j >= k * w[i]; j --) f[i][j] = max(f[i][j], max(f[i][j - k * w[i]], f[i - 1][j - k * w[i]]) + k * v[i]); for (int j = 1; j <= m; j ++) f[i][j] = max(f[i][j], f[i - 1][j]); } cout << f[n][m]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:34:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...