結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-19 21:17:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 552 ms / 5,000 ms |
| コード長 | 1,423 bytes |
| コンパイル時間 | 996 ms |
| コンパイル使用メモリ | 95,868 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 19:37:31 |
| 合計ジャッジ時間 | 5,400 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 34 |
ソースコード
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
const int INF = INT_MAX / 2;
int main()
{
int n, m;
cin >> n >> m;
vector<int> w(n);
for(int i=0; i<n; ++i)
cin >> w[i];
vector<vector<int> > dp(m+1, vector<int>(4, -INF));
dp[m][0] = 0;
for(int i=0; i<n; ++i){
vector<vector<int> > nextDp(m+1, vector<int>(4, -INF));
for(int a=0; a<=m; ++a){
for(int b=0; b<4; ++b){
nextDp[a][b&2] = max(nextDp[a][b&2], dp[a][b]);
if(a > 0){
int x = 0;
if(b & 1)
x += w[i];
if(i == n - 1 && (b & 2))
x += w[0];
if(i == 0)
nextDp[a-1][b|3] = max(nextDp[a-1][b|3], dp[a][b] + x);
else
nextDp[a-1][b|1] = max(nextDp[a-1][b|1], dp[a][b] + x);
}
}
}
dp.swap(nextDp);
}
int ans = *max_element(dp[0].begin(), dp[0].end());
cout << ans << endl;
return 0;
}