結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー |
![]() |
提出日時 | 2018-12-03 19:41:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 148 ms / 5,000 ms |
コード長 | 977 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 195,700 KB |
最終ジャッジ日時 | 2025-01-06 18:04:03 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE Int dp[2][2][3030][3030]; signed main(){ Int n,m; cin>>n>>m; vector<Int> w(n); for(Int i=0;i<n;i++) cin>>w[i]; const Int INF = 1e12; for(Int a=0;a<2;a++) for(Int b=0;b<2;b++) for(Int i=0;i<3030;i++) for(Int j=0;j<3030;j++) dp[a][b][i][j]=-INF; dp[0][0][1][0]=0; dp[1][1][1][1]=0; for(Int i=1;i<n;i++){ for(Int j=0;j<=n;j++){ for(Int a=0;a<2;a++){ for(Int b=0;b<2;b++){ chmax(dp[a][0][i+1][j],dp[a][b][i][j]); chmax(dp[a][1][i+1][j+1],dp[a][b][i][j]+b*w[i]); } } } } Int ans=dp[0][0][n][m]; for(Int a=0;a<2;a++) for(Int b=0;b<2;b++) chmax(ans,dp[a][b][n][m]+(a&&b)*w[0]); cout<<ans<<endl; return 0; }