結果

問題 No.162 8020運動
ユーザー sugim48
提出日時 2015-03-05 23:59:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4,609 ms / 5,000 ms
コード長 1,658 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 99,256 KB
実行使用メモリ 200,320 KB
最終ジャッジ日時 2024-06-24 09:44:39
合計ジャッジ時間 106,526 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int A; cin >> A;
	vector<double> p(3); cin >> p[0] >> p[1] >> p[2];
	p[0] /= 100; p[1] /= 100; p[2] /= 100;
	vector<unordered_map<int, double> > a(1 << 14);
	for (int S = 0; S < (1 << 14); S++) {
		int T = S;
		do {
			a[S][T] = 1;
			for (int i = 0; i < 14; i++) {
				if (!((S >> i) & 1)) continue;
				int cnt = 0;
				if (i - 1 >= 0 && (S >> (i - 1)) & 1) cnt++;
				if (i + 1 < 14 && (S >> (i + 1)) & 1) cnt++;
				if ((T >> i) & 1) a[S][T] *= (1 - p[cnt]);
				else a[S][T] *= p[cnt];
			}
			T = (T - 1) & S;
		} while (T != S);
	}
	vector<double> dp(1 << 14);
	dp[(1 << 14) - 1] = 1;
	for (; A < 80; A++) {
		vector<double> _dp(1 << 14);
		for (int S = 0; S < (1 << 14); S++) {
			int T = S;
			do {
				_dp[T] += dp[S] * a[S][T];
				T = (T - 1) & S;
			} while (T != S);
		}
		dp = _dp;
	}
	double ans = 0;
	for (int S = 0; S < (1 << 14); S++) {
		int cnt = 0;
		for (int i = 0; i < 14; i++)
			if ((S >> i) & 1) cnt++;
		ans += dp[S] * cnt;
	}
	printf("%.10f\n", ans * 2);
}
0