結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー |
![]() |
提出日時 | 2015-12-27 03:52:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 154 ms / 5,000 ms |
コード長 | 1,966 bytes |
コンパイル時間 | 1,368 ms |
コンパイル使用メモリ | 159,032 KB |
実行使用メモリ | 176,768 KB |
最終ジャッジ日時 | 2024-11-15 19:37:42 |
合計ジャッジ時間 | 5,477 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h>using namespace std;#undef _P#define _P(...) (void)printf(__VA_ARGS__)#define FOR(i,a,b) for (int i = (a); i < (b); i++)#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)#define REP(i,n) for (int i = 0; i < (n); i++)#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)#define ALL(x) (x).begin(), (x).end()#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)#define MP(x,y) make_pair((x), (y))#define MIN(a,b) (a < b ? a : b)#define MAX(a,b) (a > b ? a : b)#define SZ(x) ((int)(x).size())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))#define FILL_3F(a) memset(a,0x3f,sizeof(a))#define FILL_F3(a) memset(a,0xf3,sizeof(a))#define bitcount(b) __builtin_popcount(b)#define GCD(a,b) (__gcd(a,b))#define GCD3(a,b,c) (GCD(GCD(a,b), c))#define LCM(a,b) (a/GCD(a,b)*b)#define LCM3(a,b,c) LCM(LCM(a,b),c)#define MOD 1000000007template<class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }typedef long long ll;// -------------------------------------int N, M;int W[3330];int dp[3330][2][2][3330]; // pos, first, last, getint main() {cin >> N >> M;REP(i, N) cin >> W[i];FILL_F3(dp);dp[0][0][0][0] = 0;REP(p, N + 1) REP(uf, 2) REP(up, 2) REP(m, M + 1) {if (m <= M) {int fb = (p == N - 1 && uf) ? W[p] : 0;int a = (up && p >= 1) ? W[p - 1] : 0;amax(dp[p + 1][uf || p == 0][1][m + 1], dp[p][uf][up][m] + a + fb);}amax(dp[p + 1][uf][0][m], dp[p][uf][up][m]);}/*REP(p, N + 1) REP(uf, 2) REP(up, 2) REP(m, M + 1) {_P("dp[%d][%d][%d][%d] = %d\n", p, uf, up, m, dp[p][uf][up][m]);}*/int ans = -MOD;REP(uf, 2) REP(up, 2) amax(ans, dp[N][uf][up][M]);cout << ans << '\n';return 0;}