結果

問題 No.162 8020運動
ユーザー HachimoriHachimori
提出日時 2015-03-06 00:15:48
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,514 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 53,436 KB
実行使用メモリ 10,780 KB
最終ジャッジ日時 2023-09-06 15:22:19
合計ジャッジ時間 10,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,780 KB
testcase_01 AC 3,849 ms
6,280 KB
testcase_02 TLE -
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 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
using namespace std;
const int YEAR = 21;
const int TEETH = 14;
const int MASK = 1 << TEETH;


int limit;
double p[3];

void read() {
    int age;
    cin >> age;

    limit = 80 - age;
    
    int pint0, pint1, pint2;
    cin >> pint0 >> pint1 >> pint2;
    
    p[2] = pint0 * 0.01;
    p[1] = pint1 * 0.01;
    p[0] = pint2 * 0.01;
}


double rec(int year, int mask, double dp[YEAR][MASK]) {
    double &ret = dp[year][mask];
    if (ret > -0.5) return ret;
    
    if (year == limit) {
        return ret = __builtin_popcount(mask);
    }
    
    ret = 0;
    
    for (int nexMask = mask; nexMask; nexMask = (nexMask - 1) & mask) {
        
        double mul = 1;
        for (int i = 0; i < TEETH; ++i) {
            if (!(mask & (1 << i)))
                continue;

            int nMissing = 0;
            nMissing += (i == 0         || !(mask & (1 << (i - 1))));
            nMissing += (i == TEETH - 1 || !(mask & (1 << (i + 1))));
            
            if (nexMask & (1 << i)) {
                mul *= 1 - p[nMissing];
            }
            else {
                mul *= p[nMissing];
            }
        }

        ret += mul * rec(year + 1, nexMask, dp);
    }

    return ret;
}


void work() {
    static double dp[YEAR][MASK];
    for (int i = 0; i < YEAR; ++i)
        for (int j = 0; j < MASK; ++j)
            dp[i][j] = -1;
    
    printf("%.10lf\n", rec(0, (1 << TEETH) - 1, dp) * 2);
}


int main() {
    read();
    work();
    return 0;
}
0