結果

問題 No.2389 Cheating Code Golf
ユーザー t98slider
提出日時 2023-07-21 22:42:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 177,800 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 00:13:55
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

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



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<double>> dp(1 << n, vector<double>(m + 1, -1));
    vector<tuple<ll, ll, ll>> t(n);
    vector<int> a(n), b(n), p(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> p[i];
    }


    function<double(int,int)> rec = [&](int S, int j) -> double {
        if(j == m + 1) return -(1 << 30);
        if(__builtin_popcount(S) == n) return 0;
        if(dp[S][j] != -1) return dp[S][j];
        double ans = -(1 << 30);
        for(int k = 0; k < n; k++){
            if(S >> k & 1) continue;
            if(j < m) ans = max(ans, 
                (1.0 / p[k]) * (1.0 / b[k] + rec(S | (1 << k), j)) + ((double)(p[k] - 1) / p[k]) * rec(S, j + 1));
            ans = max(ans, 1.0 / a[k] + rec(S | (1 << k), j));
        }
        return dp[S][j] = ans;
    };

    cout << fixed << setprecision(15) << rec(0, 0) << '\n';
}
0