1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include<bits/stdc++.h> using namespace std;
void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; }
void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),putchar(x%10+48); } void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double #define ll long long
#define pii pair<int,int > #define vec vector<int >
#define pb push_back #define mp make_pair #define fr first #define sc second
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 1e6+10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 1e9+7;
int a,b,c,d,r,f[7900][7900],id[120][120],cnt,w;
int qpow(int a,int x) { int res=1; for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod; return res; }
void solve() { for(int i=1;i<=cnt;i++) for(int j=i+1;j<=min(cnt,i+r*2);j++) { if(!f[j][i]) continue; int t=1ll*f[j][i]*qpow(f[i][i],mod-2)%mod; for(int k=i;k<=min(cnt,i+r*2);k++) f[j][k]=(f[j][k]-1ll*t*f[i][k]%mod+mod)%mod; f[j][cnt+1]=(f[j][cnt+1]-1ll*t*f[i][cnt+1]%mod+mod)%mod; } for(int i=cnt;i;i--) { for(int j=i+1;j<=cnt;j++) f[i][cnt+1]=(f[i][cnt+1]-1ll*f[i][j]*f[j][j]%mod+mod)%mod; f[i][i]=1ll*f[i][cnt+1]*qpow(f[i][i],mod-2)%mod; } int x=id[w][w]; printf("%d\n",f[x][x]); }
int main() { read(r),read(a),read(b),read(c),read(d); int s=qpow(a+b+c+d,mod-2);w=r+2; a=1ll*a*s%mod,b=1ll*b*s%mod,c=1ll*c*s%mod,d=1ll*d*s%mod; for(int i=r;i>=-r;i--) for(int j=-r;j<=r;j++) { if(i*i+j*j>r*r) continue; id[i+w][j+w]=++cnt; } for(int i=r;i>=-r;i--) for(int j=-r;j<=r;j++) { if(i*i+j*j>r*r) continue; int x=id[i+w][j+w],t; f[x][x]=1; t=id[i-1+w][j+w];if(t) f[x][t]=mod-a; t=id[i+w][j+w-1];if(t) f[x][t]=mod-b; t=id[i+1+w][j+w];if(t) f[x][t]=mod-c; t=id[i+w][j+w+1];if(t) f[x][t]=mod-d; f[x][cnt+1]=1; } solve(); return 0; }
|