結果
問題 | No.783 門松計画 |
ユーザー |
![]() |
提出日時 | 2019-01-11 22:20:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 1,773 bytes |
コンパイル時間 | 1,913 ms |
コンパイル使用メモリ | 179,812 KB |
実行使用メモリ | 35,456 KB |
最終ジャッジ日時 | 2024-07-23 12:17:39 |
合計ジャッジ時間 | 3,107 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;using uint = unsigned int;using lint = long long int;using ulint = unsigned long long int;template<class T = int> using V = vector<T>;template<class T = int> using VV = V< V<T> >;template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }int main() {cin.tie(nullptr); ios_base::sync_with_stdio(false);int n, c; cin >> n >> c;V<> l(n); for (int i = 0; i < n; ++i) cin >> l[i];V<> w(n); for (int i = 0; i < n; ++i) cin >> w[i];if (c < 3) return cout << 0 << '\n', 0;VV< VV<> > dp; assign(dp, c + 1, c + 1, 51, 51, 0);for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (l[i] != l[j] and w[i] + w[j] <= c) {dp[2][w[i] + w[j]][l[i]][l[j]] = max(dp[2][w[i] + w[j]][l[i]][l[j]], l[i] + l[j]);}for (int i = 2; i < c; ++i) for (int j = 0; j <= c; ++j) {for (int l0 = 0; l0 <= 50; ++l0) for (int l1 = 0; l1 <= 50; ++l1) if (dp[i][j][l0][l1]) {if (l0 < l1) {for (int k = 0; k < n; ++k) if (l1 > l[k] and l0 != l[k] and j + w[k] <= c) {dp[i + 1][j + w[k]][l1][l[k]] = max(dp[i + 1][j + w[k]][l1][l[k]], dp[i][j][l0][l1] + l[k]);}} else {for (int k = 0; k < n; ++k) if (l1 < l[k] and l0 != l[k] and j + w[k] <= c) {dp[i + 1][j + w[k]][l1][l[k]] = max(dp[i + 1][j + w[k]][l1][l[k]], dp[i][j][l0][l1] + l[k]);}}}}int res = 0;for (int i = 3; i <= c; ++i) for (int j = 0; j <= c; ++j) {for (int l0 = 0; l0 <= 50; ++l0) for (int l1 = 0; l1 <= 50; ++l1) {res = max(res, dp[i][j][l0][l1]);}}cout << res << '\n';}