結果
問題 |
No.1947 質より種類数
|
ユーザー |
![]() |
提出日時 | 2022-05-20 22:47:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 624 bytes |
コンパイル時間 | 1,724 ms |
コンパイル使用メモリ | 171,676 KB |
実行使用メモリ | 198,912 KB |
最終ジャッジ日時 | 2024-09-20 09:09:27 |
合計ジャッジ時間 | 4,701 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 37 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int N,V,C; cin>>N>>V>>C; vector<int> v(N),w(N); for(int i=0;i<N;i++) cin>>v[i]>>w[i]; vector<vector<int>> dp(N+1,vector<int>(V+1)); for(int i=1;i<=N;i++){ for(int j=0;j<=V;j++){ int ans = dp[i-1][j]; if(v[i-1] <= j) ans = max(max(ans,dp[i][j-v[i-1]]+w[i-1]),dp[i-1][j-v[i-1]]+w[i-1]+C); dp[i][j] = ans; } } int ans = -1; /*for(int i=0;i<=N;i++){ for(int j=0;j<=V;j++){ cout<<dp[i][j]<<' '; } cout<<endl; }*/ for(int i=0;i<=V;i++) ans = max(ans,dp[N][i]); cout<<ans<<endl; }