[CTSC2018] 假面 | 期望 DP

题目链接

1操作怎么办呢？设$alive_i$$i$号人活着的概率，$dead_i$是他死了的概率，$g_{i,j}$是除$i$以外活了$j$个人的概率，$i$号人的答案就是$$alive_i * \sum_{j = 0}^{k - 1}\frac{1}{j + 1} * g_{i,j}$$

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#define space putchar(' ')
#define enter putchar('\n')
typedef long long ll;
using namespace std;
template <class T>
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}

const int N = 256, P = 998244353;
int n, m, K, t[N], b[N], rate[N][105], iv[N];
ll qpow(ll a, ll x){
ll ret = 1;
while(x){
if(x & 1) ret = ret * a % P;
a = a * a % P;
x >>= 1;
}
return ret;
}
void attack(int tar, ll x){
ll y = (1 - x + P) % P;
for(int i = 0; i <= b[tar]; i++){
if(i) rate[tar][i] = rate[tar][i] * y % P;
if(i < b[tar]) rate[tar][i] = (rate[tar][i] + rate[tar][i + 1] * x) % P;
}
}
void query(){
static ll f[N], g[N], h[N];
memset(f, 0, sizeof(f));
f[0] = 1;
for(int i = 1; i <= K; i++)
for(int j = i; j >= 0; j--)
f[j] = ((j ? f[j - 1] * (1 - rate[t[i]][0]) : 0) + f[j] * rate[t[i]][0]) % P;
for(int i = 1; i <= K; i++){
h[i] = 0;
if(!rate[t[i]][0])
for(int j = 0; j < K; j++)
h[i] += f[j + 1] * iv[j + 1] % P;
else{
int inv = qpow(rate[t[i]][0], P - 2);
for(int j = 0; j < K; j++){
g[j] = (f[j] - (j ? g[j - 1] * (1 - rate[t[i]][0]) : 0)) % P * inv % P;
h[i] += iv[j + 1] * g[j] % P;
}
}
h[i] %= P;
h[i] = h[i] * (1 - rate[t[i]][0]) % P;
if(h[i] < 0) h[i] += P;
}
for(int i = 1; i <= K; i++)
write(h[i]), i == K ? enter: space;
}

int main(){

for(int i = 1; i <= n; i++)
read(b[i]), rate[i][b[i]] = 1, iv[i] = qpow(i, P - 2);
int op, x, u, v;
while(m--){
else{
for(int i = 1; i <= K; i++) read(t[i]);
query();
}
}
for(int i = 1; i <= n; i++){
ll sum = 0;
for(int j = 1; j <= b[i]; j++)
sum += (ll)j * rate[i][j] % P;
write(sum % P), i == n ? enter: space;
}

return 0;
}

posted @ 2018-05-15 11:47  胡小兔  阅读(676)  评论(0编辑  收藏