제출 #659008

#제출 시각아이디문제언어결과실행 시간메모리
659008kuderRahulKnapsack (NOI18_knapsack)C++14
0 / 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,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,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(); }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   freopen("input.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   freopen("output.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...