Submission #674566

#TimeUsernameProblemLanguageResultExecution timeMemory
674566omikron123Knapsack (NOI18_knapsack)C++14
37 / 100
1063 ms1832 KiB
// https://oj.uz/problem/view/NOI18_knapsack #include <cstdio> #include <algorithm> #include <functional> #include <vector> #include <cstring> using namespace std; typedef long long ll; // 0-k背包问题 // n <= 1e5, s <= 2000 int n, s; int v[100005], w[100005], K[100005]; // v[] <= 1e6 ll dp[100005][2005]; // dp[i][j], max value achieved with items 1..i and weight j int main() { scanf("%d %d", &s, &n); for (int i = 1; i <= n; i++) scanf("%d %d %d", &v[i], &w[i], &K[i]); dp[0][0] = 0; for (int i = 1; i <= n; i++) for (int j = 0; j <= s; j++) for (int k = 0; k <= K[i]; k++) if (j-w[i]*k >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]*k] + v[i]*k); ll ans = 0; for (int i = 0; i <= s; i++) ans = max(ans, dp[n][i]); printf("%lld", ans); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d %d", &s, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d %d %d", &v[i], &w[i], &K[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...