Submission #1061259

#TimeUsernameProblemLanguageResultExecution timeMemory
1061259danglayloi1Knapsack (NOI18_knapsack)C++17
12 / 100
1 ms1884 KiB
#include <bits/stdc++.h> #define ii pair<int, int> #define fi first #define se second #define inf 0x3f3f3f3f3f3f3f3f using namespace std; using ll = long long; const ll mod=1e9+7; const int nx=105; int n, m, w[nx], v[nx], t[nx]; ll ans=0, dp[nx][2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>m>>n; for(int i = 1; i <= n; i++) cin>>v[i]>>w[i]>>t[i]; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { for(int k = 1; k <= t[i]; k++) { if(k*w[i]>j) break; dp[i][j]=max(dp[i][j], dp[i-1][j-k*w[i]]+k*v[i]); } ans=max(ans, dp[i][j]); } } cout<<ans; }
#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...