結果

問題 No.309 シャイな人たち (1)
ユーザー kimiyuki
提出日時 2015-12-03 00:53:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2,938 ms / 4,000 ms
コード長 2,277 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 71,256 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 08:14:52
合計ジャッジ時間 35,615 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <cstdio>
#include <array>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;
double por(double p, double q) { // probability or
return 1 - (1-p)*(1-q);
}
inline bool at(int s, int i) {
return s & (1 << i);
}
int main() {
int h, w; cin >> h >> w;
vector<vector<double> > p(h, vector<double>(w)); repeat (y,h) repeat (x,w) { cin >> p[y][x]; p[y][x] /= 100; }
vector<vector<int > > s(h, vector<int >(w)); repeat (y,h) repeat (x,w) cin >> s[y][x];
vector<vector<double> > dp(h+1, vector<double>(1<<w)); // dp[y][hand] = probability
dp[0][0] = 1;
repeat (y,h) {
repeat (knowledge,1<<w) {
double q = 1;
repeat (x,w) q *= at(knowledge,x) ? p[y][x] : 1 - p[y][x];
repeat (phand,1<<w) {
int hand = 0;
repeat (x,w) {
if (s[y][x] == 0 and at(knowledge,x)) hand |= (1<<x);
if (s[y][x] == 1 and at(knowledge,x) and at(phand,x)) hand |= (1<<x);
}
repeat_from (x,1,w) {
if (s[y][x] == 1 and at(knowledge,x) and at(hand,x-1)) hand |= (1<<x);
if (s[y][x] == 2 and at(knowledge,x) and at(hand,x-1) and at(phand,x)) hand |= (1<<x);
}
repeat_reverse (x,w-1) {
if (s[y][x] == 1 and at(knowledge,x) and at(hand,x+1)) hand |= (1<<x);
if (s[y][x] == 2 and at(knowledge,x) and at(hand,x+1) and at(phand,x)) hand |= (1<<x);
}
repeat_from (x,1,w-1) {
if (s[y][x] == 2 and at(knowledge,x) and at(hand,x-1) and at(hand,x+1)) hand |= (1<<x);
if (s[y][x] == 3 and at(knowledge,x) and at(hand,x-1) and at(hand,x+1) and at(phand,x)) hand |= (1<<x);
}
dp[y+1][hand] += q * dp[y][phand];
}
}
}
double result = 0;
repeat (y,h) repeat (row,1<<w) {
result += __builtin_popcount(row) * dp[y+1][row];
}
printf("%.12lf\n", result);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0