結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー |
|
提出日時 | 2018-07-09 01:18:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 99 ms / 5,000 ms |
コード長 | 2,233 bytes |
コンパイル時間 | 1,597 ms |
コンパイル使用メモリ | 168,492 KB |
実行使用メモリ | 74,368 KB |
最終ジャッジ日時 | 2024-07-08 00:44:01 |
合計ジャッジ時間 | 3,016 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 |
ソースコード
#include<bits/stdc++.h>#define rep(i,a,b) for(int i=a;i<b;i++)#define rrep(i,a,b) for(int i=a;i>=b;i--)#define fore(i,a) for(auto &i:a)#define all(x) (x).begin(),(x).end()#pragma GCC optimize ("-O3")using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }//---------------------------------------------------------------------------------------------------/*---------------------------------------------------------------------------------------------------∧_∧∧_∧ (´<_` ) Welcome to My Coding Space!( ´_ゝ`) / ⌒i/ \ | |/ / ̄ ̄ ̄ ̄/ |__(__ニつ/ _/ .| .|____\/____/ (u ⊃---------------------------------------------------------------------------------------------------*/int N, M, W[3030];//---------------------------------------------------------------------------------------------------int dp[3030][3030][2];int f(int flag) {rep(i, 0, N + 1) rep(j, 0, M + 1) rep(k, 0, 2) dp[i][j][k] = -inf;if (flag) dp[0][1][1] = 0;else dp[0][0][0] = 0;rep(i, 1, N) rep(j, 0, M + 1) {// dp[i][j][0] 取らないchmax(dp[i][j][0], dp[i - 1][j][0]);chmax(dp[i][j][0], dp[i - 1][j][1]);// dp[i][j][1] 取るif (j>0) chmax(dp[i][j][1], dp[i - 1][j - 1][0]);if (j>0) chmax(dp[i][j][1], dp[i - 1][j - 1][1] + W[i]);}int res = dp[N - 1][M][0];if (flag) chmax(res, dp[N - 1][M][1] + W[0]);else chmax(res, dp[N - 1][M][1]);return res;}//---------------------------------------------------------------------------------------------------void _main() {cin >> N >> M;rep(i, 0, N) cin >> W[i];int ans = -inf;chmax(ans, f(0));chmax(ans, f(1));cout << ans << endl;}