結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー |
![]() |
提出日時 | 2016-04-06 14:49:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 131 ms / 5,000 ms |
コード長 | 719 bytes |
コンパイル時間 | 738 ms |
コンパイル使用メモリ | 58,988 KB |
実行使用メモリ | 145,024 KB |
最終ジャッジ日時 | 2024-11-15 19:42:45 |
合計ジャッジ時間 | 7,364 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 |
ソースコード
#include <iostream>#include <algorithm>#include <cstring>using namespace std;int dp[2][3010][3010][2];int w[3010];const int mininf=0x88888888;int main(){int n, m; cin>>n>>m;for(int i=0; i<n; ++i) cin>>w[i];int res=mininf;memset(dp, 0x88, sizeof(dp));dp[0][0][0][0]=dp[1][0][1][1]=0;for(int h=0; h<2; ++h) {for(int i=1; i<n; ++i) {for(int j=0; j<=m; ++j) {dp[h][i][j][0]=max(dp[h][i-1][j][0], dp[h][i-1][j][1]);if (j)dp[h][i][j][1]=max(dp[h][i-1][j-1][0], dp[h][i-1][j-1][1]+w[i]);}}res=max({res, dp[h][n-1][m][0], dp[h][n-1][m][1]+h*w[0]});}cout<<res<<endl;}