제출 #501362

#제출 시각아이디문제언어결과실행 시간메모리
501362ala2Knapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
/* ID: alaa523 LANG: C++11 PROB: Fruit Feast */ #include <bits/stdc++.h> #define pb push_back #define int long long #define F first #define S second using namespace std; int n,s; int v[1001000]; int w[1001000]; int k[1000100]; vector<pair<int,int>>a; int dp[2001]; int dp2[2011]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); memset(dp,-1,sizeof dp); cin>>s>>n; for(int i=0; i<n; i++) { cin>>v[i]>>w[i]>>k[i]; k[i]=min(k[i],s); k[i]=min(k[i],s/w[i]+1) } for(int i=0; i<n; i++) { for(int j=0; j<k[i]; j++) { a.pb({v[i],w[i]}); } } dp[0]=0; int mx=0; for(int j=0; j<a.size(); j++) { for(int i=0;i<=s;i++) { if(dp[i]!=-1) { if(a[j].S+i>s) continue; dp2[a[j].S+i]=max(dp[a[j].S+i],dp[i]+a[j].F); } } for(int i=0;i<=s;i++) dp[i]=max(dp[i],dp2[i]); } for(int i=1; i<=s; i++) { // cout<<" "<<i<<" "<<dp[i]<<endl; mx=max(mx,dp[i]); } cout<<mx<<endl; } //dp[i]=the maxvalue we can reach with i weight //dp[i]=max(dp[i],dp[i-w[j]]+v[j]);

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:29:32: error: expected ';' before '}' token
   29 |         k[i]=min(k[i],s/w[i]+1)
      |                                ^
      |                                ;
   30 |     }
      |     ~                           
knapsack.cpp:42:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int j=0; j<a.size(); j++)
      |                  ~^~~~~~~~~