結果

問題 No.324 落ちてた閉路グラフ
ユーザー mokomoko
提出日時 2018-04-03 09:51:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,424 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 144,856 KB
実行使用メモリ 74,452 KB
最終ジャッジ日時 2023-09-08 14:04:26
合計ジャッジ時間 4,772 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
74,152 KB
testcase_01 AC 25 ms
74,140 KB
testcase_02 WA -
testcase_03 AC 25 ms
74,148 KB
testcase_04 AC 37 ms
74,200 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 36 ms
74,168 KB
testcase_09 AC 37 ms
74,276 KB
testcase_10 AC 38 ms
74,256 KB
testcase_11 AC 37 ms
74,208 KB
testcase_12 WA -
testcase_13 AC 30 ms
74,204 KB
testcase_14 WA -
testcase_15 AC 28 ms
74,344 KB
testcase_16 WA -
testcase_17 AC 26 ms
74,376 KB
testcase_18 AC 25 ms
74,344 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 26 ms
74,312 KB
testcase_22 WA -
testcase_23 AC 25 ms
74,148 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 25 ms
74,148 KB
testcase_27 AC 25 ms
74,192 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 25 ms
74,304 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int n,m,w[3000];
int dp[3010][3010][2]; // i番目の頂点まででj個の頂点を使った時の最大値。kはその頂点を使ったかどうか。

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	REP(i,3010) REP(j,3010) REP(k,2) dp[i][j][k]=-INF;

	cin>>n>>m;
	REP(i,n) cin>>w[i];
	FOR(i,1,n+1) {
		if(i==1) {
			dp[1][0][0]=dp[1][1][1]=0;
			continue;
		}
		FOR(j,1,i+1) {
			if(j<=i-2) dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1]);
			else dp[i][j][0]=dp[i-1][j][1];
			if(j==1) dp[i][j][1]=0;
			else if(j<=i-1) dp[i][j][1]=max(dp[i-1][j-1][1]+w[i-2],dp[i-1][j][0]);
			else dp[i][j][1]=dp[i-1][j-1][1]+w[i-2];
		}
	}
	int ans=-INF;
	ans=max(ans,max(dp[n][m][0],dp[n][m][1]));
	ans=max(ans,dp[n][m-1][1]+w[n-1]);
	ans=max(ans,dp[n][m-1][0]);
	cout<<ans<<endl;

	/*FOR(i,1,n+1) {
		FOR(j,0,n) printf("%2d ",dp[i][j][0]);
		printf("|");
		FOR(j,0,n+1) printf("%2d ",dp[i][j][1]);
		printf("\n");
	}*/

	return 0;
}
0