結果
| 問題 | No.309 シャイな人たち (1) |
| コンテスト | |
| ユーザー |
eitaho
|
| 提出日時 | 2015-12-02 19:57:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,056 ms / 4,000 ms |
| コード長 | 2,944 bytes |
| 記録 | |
| コンパイル時間 | 693 ms |
| コンパイル使用メモリ | 82,356 KB |
| 実行使用メモリ | 20,096 KB |
| 最終ジャッジ日時 | 2024-09-14 08:01:14 |
| 合計ジャッジ時間 | 16,298 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }
const int MaxSize = 11;
const int Threshold = 4;
int H, W;
double Prob[MaxSize][MaxSize];
int Val[MaxSize][MaxSize];
int AtLast[1 << MaxSize * 2];
double dp[1 << MaxSize], nextdp[1 << MaxSize];
void simulate() {
int S = 1 << W * 2;
int pt[MaxSize];
int who[MaxSize], nextWho[MaxSize];
rep(mask, S) {
int num = 0;
for (int c = 0; c < W; c++) {
pt[c] = 1 + (mask >> c * 2 & 3);
if (pt[c] == Threshold) {
who[num++] = c;
AtLast[mask] += 1 << c;
}
}
while (num > 0) {
int nextNum = 0;
rep(i, num) {
int c = who[i];
if (c - 1 >= 0 && ++pt[c - 1] == Threshold) {
nextWho[nextNum++] = c - 1; AtLast[mask] += 1 << c - 1;
}
if (c + 1 < W && ++pt[c + 1] == Threshold) {
nextWho[nextNum++] = c + 1; AtLast[mask] += 1 << c + 1;
}
}
swap(who, nextWho);
num = nextNum;
}
}
}
void solve() {
simulate();
dp[0] = 1;
double ans = 0;
rep(r, H) {
memset(nextdp, 0, sizeof(nextdp));
rep(currMask, 1 << W) {
double currMaskProb = 1;
rep(c, W) {
if (currMask >> c & 1) currMaskProb *= Prob[r][c];
else currMaskProb *= 1 - Prob[r][c];
}
rep(prevMask, 1 << W) if (dp[prevMask] > 0) {
double p = dp[prevMask] * currMaskProb;
int key = 0;
rep(c, W) {
int pt = Val[r][c] * (currMask >> c & 1);
if (r > 0) pt += prevMask >> c & 1;
key |= max(0, min(Threshold, pt) - 1) << c * 2;
}
int nextMask = AtLast[key];
ans += p * __builtin_popcount(nextMask);
nextdp[nextMask] += p;
}
}
swap(dp, nextdp);
}
printf("%.11f\n", ans);
}
int main() {
cin >> H >> W;
rep(r, H) rep(c, W) {
cin >> Prob[r][c];
Prob[r][c] /= 100.0;
}
rep(r, H) rep(c, W) {
cin >> Val[r][c];
Val[r][c] = Threshold - Val[r][c];
}
solve();
return 0;
}
eitaho