Submission #659005

#TimeUsernameProblemLanguageResultExecution timeMemory
659005kuderRahulKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int #define v vector const int N = 1e6 + 111, mod = 1e9 + 7; void solve() { int n,s,k,a,b,c; cin>>s>>n; if(n==1){ cin>>a>>b>>c; cout<<min(s/b,c)*a<<'\n'; return; } v<int>weight(n+1),value(n+1),itemCount(n+1); for(int i=0;i<n;i++)cin>>value[i]>>weight[i]>>itemCount[i]; v<v<int>>dp(n+11,v<int>(s+11,0)); for(int i=0;i<=n;i++)dp[0][i]=0; for(int i=1;i<=n;i++) for(int j=1;j<=s;j++) for(int x=0;x<=itemCount[i-1];x++) if(j-x*weight[i-1]>=0)dp[i][j]=max(dp[i][j],value[i-1]*x+dp[i-1][j-x*weight[i-1]]); cout<<dp[n][s]; } signed main() { // freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); // int t;scanf("%lld",&t);while(t--) solve(); }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:7:11: warning: unused variable 'k' [-Wunused-variable]
    7 |   int n,s,k,a,b,c;
      |           ^
#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...