結果

問題 No.2389 Cheating Code Golf
ユーザー RubikunRubikun
提出日時 2023-07-21 21:33:15
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,553 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 201,736 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-21 22:52:19
合計ジャッジ時間 3,596 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=1LL<<60;

bool seen[55][1<<12];
double dp[55][1<<12];

int N,M;
double A[13],B[13],P[13];

double solve(int rem,int ok){
    if(seen[rem][ok]) return dp[rem][ok];
    if(ok==((1<<N)-1)) return 0;
    
    seen[rem][ok]=true;
    
    if(rem==0){
        double ans=0;
        for(int i=0;i<N;i++){
            if(!(ok&(1<<i))){
                if(P[i]==1) ans+=max(A[i],B[i]);
                else ans+=A[i];
            }
        }
        
        return dp[rem][ok]=ans;
    }
    
    double ma=0;
    for(int i=0;i<N;i++){
        if(ok&(1<<i)) continue;
        
        double a=solve(rem,ok|(1<<i))+A[i];
        double b=P[i]*(solve(rem,ok|(1<<i))+B[i])+(1.0-P[i])*solve(rem-1,ok);
        
        chmax(ma,a);
        chmax(ma,b);
    }
    
    return dp[rem][ok]=ma;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    for(int i=0;i<N;i++){
        int a,b,p;cin>>a>>b>>p;
        A[i]=(1.0)/a;
        B[i]=(1.0)/b;
        P[i]=(1.0)/p;
    }
    
    cout<<fixed<<setprecision(25)<<solve(M,0)<<endl;
}
0