結果

問題 No.324 落ちてた閉路グラフ
ユーザー imulanimulan
提出日時 2016-09-21 03:51:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,330 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 168,924 KB
実行使用メモリ 144,484 KB
最終ジャッジ日時 2024-04-28 16:41:00
合計ジャッジ時間 4,658 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
144,412 KB
testcase_01 AC 36 ms
144,324 KB
testcase_02 AC 35 ms
144,292 KB
testcase_03 AC 35 ms
144,292 KB
testcase_04 AC 54 ms
144,272 KB
testcase_05 AC 81 ms
144,336 KB
testcase_06 AC 51 ms
144,288 KB
testcase_07 AC 76 ms
144,424 KB
testcase_08 AC 52 ms
144,292 KB
testcase_09 AC 45 ms
144,264 KB
testcase_10 AC 52 ms
144,452 KB
testcase_11 AC 42 ms
144,364 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 35 ms
144,400 KB
testcase_14 AC 39 ms
144,292 KB
testcase_15 AC 42 ms
144,408 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 37 ms
144,300 KB
testcase_18 AC 36 ms
144,272 KB
testcase_19 AC 55 ms
144,336 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 35 ms
144,256 KB
testcase_22 AC 36 ms
144,404 KB
testcase_23 AC 36 ms
144,272 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 81 ms
144,272 KB
testcase_26 AC 35 ms
144,332 KB
testcase_27 AC 37 ms
144,280 KB
testcase_28 AC 36 ms
144,376 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 35 ms
144,376 KB
testcase_31 AC 37 ms
144,376 KB
testcase_32 AC 80 ms
144,316 KB
testcase_33 AC 72 ms
144,276 KB
testcase_34 AC 52 ms
144,308 KB
testcase_35 AC 36 ms
144,392 KB
testcase_36 AC 40 ms
144,484 KB
testcase_37 AC 37 ms
144,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int INF=12345678;
const int N=3000;

int dp[3001][3001][2][2];

int main()
{
    int n,m;
    scanf(" %d %d", &n, &m);
    vector<int> w(n);
    rep(i,n) scanf(" %d", &w[i]);

    if(m==0) printf("0\n");
    else
    {
        rep(i,3001)rep(j,3001)rep(k,2)rep(l,2) dp[i][j][k][l]=-INF;
        dp[0][0][0][0]=0;
        dp[0][1][1][1]=0;

        rep(i,n-1)rep(j,m+1)
        {
            // i番目を選ばない
            rep(before,2)rep(one,2) dp[i+1][j][0][one] = max(dp[i+1][j][0][one], dp[i][j][before][one]);

            // 選ぶ
            if(j<m)
            {
                rep(before,2)rep(one,2)
                {
                    int add=0;
                    if(before) add+=w[i];
                    if(i==n-2 && one) add+=w[n-1];
                    dp[i+1][j+1][1][one] = max(dp[i+1][j+1][1][one], dp[i][j][before][one]+add);
                }
            }
        }

        int ans=-INF;
        rep(i,2)rep(j,2) ans=max(ans,dp[n-1][m][i][j]);
        printf("%d\n", ans);
    }
    return 0;
}
0