結果

問題 No.2167 Fibonacci Knapsack
ユーザー norikamenorikame
提出日時 2022-12-19 20:10:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,164 bytes
コンパイル時間 5,557 ms
コンパイル使用メモリ 314,348 KB
実行使用メモリ 310,876 KB
最終ジャッジ日時 2024-04-29 02:24:45
合計ジャッジ時間 8,768 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

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; }

const int INF = (int)(1e9);

int main() {
	int t0;
	cin >> t0;
	rep(i0, t0) {
		int n;
		ll w;
		cin >> n >> w;
		vector<ll> wi(n);
		rep(i, n) cin >> wi[i];
		vector<ll> fib(n);
		rep(i, n) {
			if (i == 0) fib[i] = 1;
			else if (i == 1) fib[i] = 2;
			else fib[i] = fib[i-2] + fib[i-1];
		}
		unordered_map<ll, ll> vals;
		ll res = 0;
		vals[0] = 0;
		repr(i, n) {
			auto pvals = vals;
			for (const auto& pi : pvals) if (pi.first+wi[i] <= w) {
				chmax(vals[pi.first+wi[i]], pi.second+fib[i]);
				res = max(res, pi.second+fib[i]);
			}
		}
		cout << res << endl;
	}
	return 0;
}
0