Submission #601407

#TimeUsernameProblemLanguageResultExecution timeMemory
601407codergirlKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=100005; int c[maxn],value[maxn],num[maxn], dp[maxn]; int V; void ZeroOnePack (int cost,int val){ for(int i=V;i>=cost;i--) { dp[i]=max(dp[i],dp[i-cost] + val); } return ; } int main() { int n; cin>>V>>n; // knapsack size V, n kinds of items for(int i=1;j<=n;j++) { cin>>value[i]>>c[i]>>num[i]; // weight, value, quantity } for(int i=1;i<=n;i++) { int k=1; while(k<num[i]){ ZeroOnePack(k * c[i], k * value[i]); num[i]-=k; k*=2; } ZeroOnePack(num[i]*c[i],num[i]*value[i]); } cout<<dp[V]<<'\n'; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:18:17: error: 'j' was not declared in this scope
   18 |     for(int i=1;j<=n;j++) {
      |                 ^