Submission #1061270

#TimeUsernameProblemLanguageResultExecution timeMemory
1061270danglayloi1Knapsack (NOI18_knapsack)C++17
73 / 100
165 ms2136 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++) { dp[i][j]=dp[i-1][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]); } } } cout<<dp[n][m]; }
#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...