結果
問題 | No.783 門松計画 |
ユーザー |
|
提出日時 | 2019-01-12 12:06:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 1,091 bytes |
コンパイル時間 | 1,740 ms |
コンパイル使用メモリ | 169,848 KB |
実行使用メモリ | 15,548 KB |
最終ジャッジ日時 | 2024-07-23 12:18:58 |
合計ジャッジ時間 | 2,847 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for (int i=0;i<(n);i++) #define REP2(i,m,n) for (int i=m;i<(n);i++) typedef long long ll; typedef long double ld; typedef vector<int> VI; typedef vector<ll> VL; int N, C; int L[55]; int W[55]; int dp[51][51][51][51]; bool ok[51][51][51][51]; bool is_kadomatsu(int a, int b, int c) { return a != b && b != c && c != a && ((a < b && b > c) || (a > b && b < c)); } void solve() { cin >> N >> C; REP(i, N) cin >> L[i]; REP(i, N) cin >> W[i]; int ans = 0; ok[0][0][0][0] = true; REP(a, 50) REP(b, C) REP(c, N) REP(d, N) if (ok[a][b][c][d]) REP(e, N) if (b + W[e] <= C) { if (a == 1 && L[d] == L[e]) continue; if (a > 1 && !is_kadomatsu(L[c], L[d], L[e])) continue; dp[a+1][b+W[e]][d][e] = max(dp[a+1][b+W[e]][d][e], dp[a][b][c][d] + L[e]); ok[a+1][b+W[e]][d][e] = true; } REP2(a, 3, 51) REP(b, 51) REP(c, 51) REP(d, 51) ans = max(ans, dp[a][b][c][d]); cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }