結果

問題 No.324 落ちてた閉路グラフ
ユーザー mokomoko
提出日時 2018-04-04 15:54:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,747 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 145,852 KB
実行使用メモリ 74,488 KB
最終ジャッジ日時 2023-09-08 15:50:01
合計ジャッジ時間 5,825 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 38 ms
74,148 KB
testcase_02 AC 38 ms
74,136 KB
testcase_03 AC 38 ms
74,140 KB
testcase_04 AC 76 ms
74,220 KB
testcase_05 AC 76 ms
74,488 KB
testcase_06 WA -
testcase_07 AC 78 ms
74,440 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 77 ms
74,240 KB
testcase_12 AC 73 ms
74,224 KB
testcase_13 WA -
testcase_14 AC 41 ms
74,328 KB
testcase_15 AC 44 ms
74,144 KB
testcase_16 AC 38 ms
74,208 KB
testcase_17 WA -
testcase_18 AC 38 ms
74,216 KB
testcase_19 AC 38 ms
74,264 KB
testcase_20 AC 38 ms
74,132 KB
testcase_21 WA -
testcase_22 AC 39 ms
74,156 KB
testcase_23 AC 39 ms
74,268 KB
testcase_24 AC 38 ms
74,204 KB
testcase_25 AC 38 ms
74,268 KB
testcase_26 AC 38 ms
74,140 KB
testcase_27 AC 39 ms
74,128 KB
testcase_28 AC 39 ms
74,208 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 39 ms
74,268 KB
testcase_32 AC 77 ms
74,240 KB
testcase_33 AC 78 ms
74,156 KB
testcase_34 WA -
testcase_35 AC 38 ms
74,152 KB
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[3010];
int dp[3010][3010][2]; //頂点iまででj個の頂点を使ったときの最大値。kは頂点iを使ったかどうか。
int ans=-INF;

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

	REP(i,3010) FOR(j,1,3010) dp[i][j][0]=dp[i][j][1]=-INF;

	cin>>n>>m;
	REP(i,n) cin>>w[i+1];

	// 頂点1を使わない
	dp[1][0][0]=0;
	FOR(i,1,n+1) {
		FOR(j,0,n+1) {
			// 頂点i+1を使わない
			dp[i+1][j][0]=max(dp[i+1][j][0],max(dp[i][j][0],dp[i][j][1]));
			// 頂点i+1を使う
			dp[i+1][j+1][1]=max(dp[i+1][j+1][1],max(dp[i][j][0],dp[i][j][1]+w[i]));
		}
		ans=max(ans,dp[i][m][0]);
	}
	ans=dp[n+1][m][0]; // 頂点1=n+1

	REP(i,3010) FOR(j,1,3010) dp[i][j][0]=dp[i][j][1]=-INF;

	// 頂点1を使う。
	dp[1][1][1]=0;
	FOR(i,1,n+1) {
		FOR(j,1,n+1) {
			// 頂点iを使わない
			dp[i+1][j][0]=max(dp[i+1][j][0],max(dp[i][j][0],dp[i][j][1]));
			// 頂点iを使う
			dp[i+1][j+1][1]=max(dp[i+1][j+1][1],max(dp[i][j][0],dp[i][j][1]+w[i]));
		}
		if(i==n) ans=max(ans,dp[n][m][1]+w[n]);
		else ans=max(ans,dp[i][m][1]);
	}

	/*FOR(i,1,n+1) {
		REP(j,n+1) cout<<(dp[i][j][0]>=0?dp[i][j][0]:-1)<<' ';
		cout<<'|';
		REP(j,n+1) cout<<(dp[i][j][1]>=0?dp[i][j][1]:-1)<<' ';
		cout<<endl;
	}*/

	cout<<ans<<endl;

	return 0;
}
0