結果
問題 |
No.324 落ちてた閉路グラフ
|
ユーザー |
![]() |
提出日時 | 2016-05-18 19:35:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 422 ms / 5,000 ms |
コード長 | 553 bytes |
コンパイル時間 | 1,609 ms |
コンパイル使用メモリ | 159,004 KB |
実行使用メモリ | 145,280 KB |
最終ジャッジ日時 | 2024-11-15 19:42:55 |
合計ジャッジ時間 | 7,663 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; int w[3010]; int n,m; int dp[3010][3010][2][2]; int dfs(int x,int y,int u,int f){ if( y < 0 ) return -1e9; if( x == n ){ if( y != 0 ) return -1e9; return f == 1 && u == 1 ? w[n-1] : 0; } if( dp[x][y][u][f] != -1 ) return dp[x][y][u][f]; int ans = -1e9; ans = max(dfs(x+1,y,0,f),dfs(x+1,y-1,1,f)+(u*w[x-1])); return dp[x][y][u][f] = ans; } int main(){ cin >> n >> m; for(int i = 0 ; i < n ; i++) cin >> w[i]; memset(dp,-1,sizeof(dp)); cout << max(dfs(1,m,0,0),dfs(1,m-1,1,1)) << endl; }