結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| コンテスト | |
| ユーザー |
moko_freedom
|
| 提出日時 | 2018-04-03 09:51:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,424 bytes |
| コンパイル時間 | 2,534 ms |
| コンパイル使用メモリ | 159,704 KB |
| 実行使用メモリ | 74,464 KB |
| 最終ジャッジ日時 | 2024-06-26 07:11:08 |
| 合計ジャッジ時間 | 5,352 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 14 WA * 20 |
ソースコード
#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;
}
moko_freedom