結果
問題 | No.309 シャイな人たち (1) |
ユーザー |
|
提出日時 | 2023-05-16 02:23:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,791 bytes |
コンパイル時間 | 1,831 ms |
コンパイル使用メモリ | 177,268 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 06:29:05 |
合計ジャッジ時間 | 30,138 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector<vector<double>> P(h, vector<double>(w)); vector<vector<int>> S(h, vector<int>(w)); for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ cin >> P[y][x]; P[y][x] /= 100; } } for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ cin >> S[y][x]; } } vector<double> pre(1 << w); pre[0] = 1; auto f = [&](int S0, int S1, int x){ int cnt = 0; cnt += (S0 >> x) & 1; if(x) cnt += (S1 >> x - 1) & 1; cnt += (S1 >> x + 1) & 1; return cnt; }; double ans = 0; for(int y = 0; y < h; y++){ //前の列手を挙げている人がS0でS1に遷移する確率 vector<double> dp(1 << w); for(int S0 = 0; S0 < (1 << w); S0++){ if(pre[S0] == 0) continue; for(int S1 = 0; S1 < (1 << w); S1++){ double p = pre[S0], p0, p1; for(int x = 0; x < w; x++){ p0 = p1 = 0; int c = f(S0, S1, x); if(S1 >> x & 1){ if(4 - S[y][x] + c >= 4) p0 = P[y][x] * p; if(c >= 4) p1 = (1 - P[y][x]) * p; }else{ if(4 - S[y][x] + c < 4) p0 = P[y][x] * p; if(c < 4) p1 = (1 - P[y][x]) * p; } p = p0 + p1; } dp[S1] += p; ans += p * __builtin_popcount(S1); } } swap(pre, dp); } cout << fixed << setprecision(15) << ans << '\n'; }