結果

問題 No.2167 Fibonacci Knapsack
ユーザー t98slidert98slider
提出日時 2022-12-19 02:26:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,052 bytes
コンパイル時間 3,998 ms
コンパイル使用メモリ 168,352 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 09:24:45
合計ジャッジ時間 3,548 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<ll> fib(77);
    fib[0] = 1;
    fib[1] = 2;
    for(int i = 2; i < 77; i++)fib[i] = fib[i - 1] + fib[i - 2];
    int T;
    cin >> T;
    while(T--){
        int n;
        ll W;
        cin >> n >> W;
        vector<ll> a(n), s(n + 1);
        for(int i = 0; i < n; i++){
            cin >> a[i];
            s[i + 1] = s[i] + a[i];
        }
        ll ans = 0;
        for(int l = 0; l < n; l++){
            for(int r = l; r < n; r++){
                ll w = W - (s[r + 1] - s[l]);
                ll v = fib[r + 2] - fib[l + 1];
                if(w < 0)continue;
                for(int j = n - 1; j >= 0; j--){
                    if(l <= j && j <= r)continue;
                    if(w >= a[j]){
                        w -= a[j];
                        v += fib[j];
                    }
                }
                ans = max(ans, v);
            }
        }
        cout << ans << '\n';
    }
}
0