結果

問題 No.309 シャイな人たち (1)
ユーザー yosupotyosupot
提出日時 2015-12-02 01:12:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,782 ms / 4,000 ms
コード長 1,717 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 69,128 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 08:36:40
合計ジャッジ時間 42,965 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,478 ms
4,348 KB
testcase_01 AC 2,782 ms
4,348 KB
testcase_02 AC 2,245 ms
4,352 KB
testcase_03 AC 2,706 ms
4,352 KB
testcase_04 AC 2,564 ms
4,348 KB
testcase_05 AC 2,542 ms
4,348 KB
testcase_06 AC 2,229 ms
4,348 KB
testcase_07 AC 2,335 ms
4,348 KB
testcase_08 AC 2,677 ms
4,348 KB
testcase_09 AC 2,702 ms
4,352 KB
testcase_10 AC 2,590 ms
4,348 KB
testcase_11 AC 2,522 ms
4,352 KB
testcase_12 AC 2,492 ms
4,348 KB
testcase_13 AC 2,064 ms
4,352 KB
testcase_14 AC 2,064 ms
4,352 KB
testcase_15 AC 2,154 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cassert>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;


const int MN = 11;
const int r = 11;
const int c = 11;
int main() {
	int rr, cc;
	cin >> rr >> cc;
	static double p[MN][MN];
	static int s[MN][MN];
	for (int i = 0; i < rr; i++) {
		for (int j = 0; j < cc; j++) {
			cin >> p[i][j];
			p[i][j] /= 100.0;
		}
	}
	for (int i = 0; i < rr; i++) {
		for (int j = 0; j < cc; j++) {
			cin >> s[i][j];
			s[i][j] = 4-s[i][j];
		}
	}

	double dp1[1<<MN] = {}, dp2[1<<MN] = {};
	double sm = 0;
	dp1[0] = 1.0;
	for (int i = 0; i < r; i++) {
		fill_n(dp2, 1<<MN, 0.0);
		for (int l = 0; l < (1<<c); l++) {
			double pp = 1;
			for (int m = 0; m < c; m++) {
				if (l & (1<<m)) {
					pp *= p[i][m];
				} else {
					pp *= 1.0-p[i][m];
				}
			}
			for (int k = 0; k < (1<<c); k++) {
				int ll = 0;
				bool back = false;
				for (int m2 = 1, *ss = s[i]; m2 < (1<<c); m2<<=1, ss++) {
					int u = 0;
					if (l & m2) u = *ss;
					if (back) u++;
					if (k & m2) u++;
					if (u >= 4) {
						ll |= m2;
						back = true;
					} else {
						back = false;
					}
				}
				back = false;
				for (int m2 = 1<<(c-1), *ss = s[i+1]-1; m2 >= 1; m2>>=1, ss--) {
					int u = 0;
					if (l & m2) u = *ss;
					if (k & m2) u++;
					if (back) u++;
					if (ll & (m2>>1)) u++;
					if (u >= 4 || (ll & m2)) {
						ll |= m2;
						back = true;
					} else {
						back = false;
					}
				}
				dp2[ll] += dp1[k]*pp;
			}
		}
		for (int j = 0; j < (1<<c); j++) {
			dp1[j] = dp2[j];
			sm += dp2[j] * __builtin_popcount(j);
		}

	}
	printf("%.20lf\n", sm);
	return 0;
}
0