結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2015-12-17 12:43:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 5,000 ms |
| コード長 | 1,178 bytes |
| コンパイル時間 | 1,413 ms |
| コンパイル使用メモリ | 161,492 KB |
| 実行使用メモリ | 73,868 KB |
| 最終ジャッジ日時 | 2024-11-15 19:33:56 |
| 合計ジャッジ時間 | 4,160 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef int LL;
typedef vector<LL> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
#define USED 1
#define UNUSED 0
const LL INF=((LL)1e8);
int dp[3000][3001][2];
inline void init(){
for(int i=0;i<3000;i++)
for(int j=0;j<=3000;j++)
for(int k=0;k<2;k++)dp[i][j][k]=-INF;
}
int main() {
int n,m;cin>>n>>m;
V w(n);for(auto& it : w)cin>>it;
LL res=-INF;
init();dp[0][0][UNUSED]=0;
for(int i = 1; i < n; i++){
for(int j=0;j<=m;j++){
if(j<m)dp[i][j+1][USED]=max(dp[i-1][j][USED]+w[i-1],dp[i-1][j][UNUSED]);
dp[i][j][UNUSED]=max(dp[i-1][j][USED],dp[i-1][j][UNUSED]);
}
}
for(int i=max(0,m-1);i<n;i++)for(int j=0;j<2;j++)res=max(res,dp[i][m][j]);
init();dp[0][1][USED]=0;
for(int i = 1; i < n; i++){
for(int j=0;j<=m;j++){
if(j<m)dp[i][j+1][USED]=max(dp[i-1][j][USED]+w[i-1],dp[i-1][j][UNUSED]);
dp[i][j][UNUSED]=max(dp[i-1][j][USED],dp[i-1][j][UNUSED]);
}
}
dp[n-1][m][USED]+=w[n-1];
for(int i=max(0,m-1);i<n;i++)for(int j=0;j<2;j++)res=max(res,dp[i][m][j]);
cout<<res<<endl;
return 0;
}
btk