結果
| 問題 | No.324 落ちてた閉路グラフ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-18 03:26:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,868 bytes |
| 記録 | |
| コンパイル時間 | 877 ms |
| コンパイル使用メモリ | 94,496 KB |
| 実行使用メモリ | 817,536 KB |
| 最終ジャッジ日時 | 2024-09-16 08:25:38 |
| 合計ジャッジ時間 | 3,072 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | MLE * 1 -- * 33 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
#define mp make_pair
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
if(p){
cout << fixed << setprecision(p) << a << "\n";
}
else{
cout << a << "\n";
}
}
// end of template
int main() {
cin.tie(0);
// source code
ll N, M;
cin >> N >> M;
vector<ll> W(N);
rep(i, N){
cin >> W[i];
}
vector<vector<vector<vector<ll>>>> dp(N, vector<vector<vector<ll>>> (N + 1, vector<vector<ll>>(2, vector<ll> (2, -inf)))); // [いくつまで選んだか][何個選んだか][今いる頂点を選んだか][0番目を選んだか]
dp[0][0][0][0] = 0; dp[0][1][1][1] = 0;
repd(i, 1, N){
rep(j, i + 2){
rep(z, 2){
dp[i][j][0][z] = max(dp[i - 1][j][0][z], dp[i - 1][j][1][z]);
if(j) dp[i][j][1][z] = max(dp[i - 1][j - 1][0][z], dp[i - 1][j - 1][1][z] + W[i - 1]);
}
}
}
rep(j, N + 1){
rep(z, 2){
dp[N - 1][j][0][z] = max(dp[N - 2][j][0][z], dp[N - 2][j][1][z]);
}
if(j){
dp[N - 1][j][1][1] = max(dp[N - 2][j - 1][0][1], dp[N - 2][j - 1][1][1] + W[N - 2]) + W[N - 1];
dp[N - 1][j][1][0] = max(dp[N - 2][j - 1][0][0], dp[N - 2][j - 1][1][0] + W[N - 2]);
}
}
ll ret = -inf;
rep(y, 2) rep(z, 2) ret = max(ret, dp[N - 1][M][y][z]);
output(ret, 0);
return 0;
}