Submission #618109

#TimeUsernameProblemLanguageResultExecution timeMemory
618109NafeeszxKnapsack (NOI18_knapsack)C++17
73 / 100
543 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define trav(a, x) for(auto& a : x) #define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++) #define ROF(i, a, b) for (int i=(a); i>=(signed)(b); i--) #define F0R(i, a) for (int i=0; i<(signed)(a); i++) #define vi vector<int> #define vvl vector<vector<ll>> #define all(v) (v).begin(),(v).end() typedef long long ll; void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if(name.size()){ freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } const int mod = 1e9 + 7, MOD = 998244353; int dp[100000][2001]; int main() { setIO(); int s, n; cin >> s >> n; vector<int> v(n), w(n), k(n); F0R(i, n) cin >> v[i] >> w[i] >> k[i]; for(int t = 0; t * w[0] <= s && t <= k[0]; ++t) dp[0][t*w[0]] = t * v[0]; F0R(i, n-1) { FOR(j, 0, s) { for(int t = 0; j + t * w[i+1] <= s && t <= k[i+1]; ++t) { dp[i+1][j+t*w[i+1]] = max(dp[i+1][j+t*w[i+1]], dp[i][j] + t * v[i+1]); } } } int res = 0; //for(int j = 0; j < n; ++j) { for(int i = 0; i <= s; ++i) { res = max(res, dp[n-1][i]); //cout << dp[j][i] << " "; } //cout << "\n"; //} cout << res; //cout << dp[0][12]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen((name+".out").c_str(), "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...