#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
#define re register
const int mod=1e9+7;
const int N=210;
template<typename tp>inline void read(tp&x)
{
x=0;re int f=0;re char ch=getchar();
while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
if(f)x=-x;
}
template<typename tp>inline void write(tp x)
{
re int buf[40],p=0;
if(x<0)putchar('-'),x=-x;
do{
buf[p++]=x%10;x/=10;
}while(x);
for(re int i=p-1;i+1;i--)putchar(buf[i]+48);
putchar(' ');
}
template<typename tp>inline ll mul(tp x,tp y){return 1ll*x*y%mod;}
int n,m;
ll a,b,g[N][N];
ll qpow(ll a,ll b)
{
ll ret=1;a%=mod;
for(;b;b>>=1)
{
if(b&1)ret=mul(ret,a);
a=mul(a,a);
}
return ret;
}
int main()
{
//freopen("in.txt","r",stdin);
read(n);read(m);
for(re int i=1;i<=n;i++)
for(re int j=1;j<=m;j++)
{
read(a);read(b);g[i][j]=mul(a,qpow(b,mod-2));//堵塞概率
}
for(re int i=1;i<=n;i++)
{
for(re int j=1;j<=m;j++)
{
re ll t=min(min(i,j),min(n-i+1,m-j+1));
re ll ans=0,p=g[i][j],q=g[i][j];
for(re int k=1;k<t;k++)//一个格子需要清理的次数的期望等于需要清理至少1次的概率加
//需要清理至少2次的概率加需要清理至少3次的概率加…
{
for(re int l=i-k;l<=i+k;l++)
if(abs(i-l)==k)p=mul(p,g[l][j]);
else p=mul(mul(p,g[l][j-k+abs(i-l)]),g[l][j+k-abs(i-l)]);//乘上曼哈顿距离等于k被堵的概率
ans=(ans+k*(q-p+mod))%mod;
q=p;
}
ans=(ans+t*p)%mod;write(ans);
}
puts("");
}
return 0;
}
总结
求期望的好题