結果

問題 No.324 落ちてた閉路グラフ
ユーザー ctyl_0ctyl_0
提出日時 2015-12-18 03:19:27
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,870 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 97,824 KB
実行使用メモリ 813,880 KB
最終ジャッジ日時 2023-10-14 13:44:15
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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
    int N, M;
    cin >> N >> M;
    vector<int> 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;
}
0