結果

問題 No.324 落ちてた閉路グラフ
ユーザー FF256grhyFF256grhy
提出日時 2015-12-17 04:30:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 26,352 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 12:15:30
合計ジャッジ時間 2,588 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int n, m, w[3000];
int dp[3001][4];

int max(int a, int b) { return (a > b ? a : b); }

int main(void) {
	scanf("%d%d", &n, &m);
	
	if(m < 2) { printf("0\n"); return 0; }
	
	int i, j;
	for(i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	
	dp[0][3] = w[0];
	for(i = 2; i < n; i++) {
	for(j = i - 1; 0 <= j; j--) {
		int a = dp[j - 1][3], b = dp[j - 1][1];
		int w1 = w[i - 1], w2 = (i == n - 1 ? w[i] : 0);
		if(j == i - 1) {
			dp[j][3] = a + w1 + w2;
			dp[j][2] = a;
			dp[j][1] = b + w1;
			dp[j][0] = b;
		} else if(j == 0) {
			dp[0][3] = w2;
		} else {
			dp[j][3] = max(dp[j][2], a + w1) + w2;
			dp[j][2] = max(dp[j][2], a);
			dp[j][1] = max(dp[j][0], b + w1);
			dp[j][0] = max(dp[j][0], b);
		}
	}
	}
	
	printf("%d\n", max( max(dp[m][0], dp[m - 1][1]), max(dp[m - 1][2], dp[m - 2][3]) ) );
	
	return 0;
}
0