結果

問題 No.324 落ちてた閉路グラフ
ユーザー h_nosonh_noson
提出日時 2016-06-19 18:09:26
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,079 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 65,360 KB
実行使用メモリ 47,744 KB
最終ジャッジ日時 2024-04-19 20:37:38
合計ジャッジ時間 7,178 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 TLE -
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 <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int dp[3001][3000][2];
int w[3000];
int n;

int dfs(int v, int m, bool fst) {
    if (dp[v][m][fst] != -2*INF)
        return dp[v][m][fst];
    if (v < n-1) {
        if (m > 0) {
            int i, ret = w[v] + dfs(v+1,m-1,fst);
            REP (i,v+2,n-1) ret = max(ret,dfs(i,m-1,fst));
            return dp[v][m][fst] = ret;
        }
        else
            return 0;
    }
    else if (m > 0)
        return -INF;
    else
        return fst ? w[n-1] : 0;
}

int main(void) {
    int i, j, m;
    cin >> n >> m;
    rep (i,n) cin >> w[i];
    rep (i,n+1) rep (j,m) dp[i][j][0] = dp[i][j][1] = -2*INF;
    int ans = dfs(0,m-1,true);
    REP (i,1,n) {
        ans = max(ans,dfs(i,m-1,false));
    }
    cout << ans << endl;
    return 0;
}
0