#include<bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long LL; typedef pair<int, int> P; const int mod = 1e9 + 7; const int maxn = 8005; int add(int x, int y) { x += y; return x; } int mul(int x, int y) { LL z = 1LL * x * y; return z - z / mod * mod; } int powt(int a, int b) { int r = 1; while(b) { if(b & 1) r = mul(r, a); a = mul(a, a); b >>= 1; } return r; } int f[maxn][maxn]; int id[111][111], a[4], dx[4] = { -1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; vector<int> c; int main() { #ifdef CX_TEST freopen("E:program--GG est_in.txt", "r", stdin); #endif int n = 0, r, i, j, k, x, y, u, v; scanf("%d", &r); for(i = j = 0; i < 4; i++) { scanf("%d", &a[i]); j += a[i]; } j = powt(j, mod - 2); for(i = 0; i < 4; i++) a[i] = mod - mul(a[i], j); for(i = -r; i <= r; i++) { for(j = -r; j <= r; j++) { if(i * i + j * j <= r * r) id[i + 55][j + 55] = ++n; } } for(i = -r; i <= r; i++) { for(j = -r; j <= r; j++) { if(u = id[i + 55][j + 55]) { f[u][0] = f[u][u] = 1; for(k = 0; k < 4; k++) { x = i + dx[k]; y = j + dy[k]; if(v = id[x + 55][y + 55]) f[u][v] = a[k]; } } } } for(i = 1;i <= n; i++) { u = min(n, i + r * 2 + 1); c.clear(); c.push_back(0); for(j = i;j <= u; j++) { if(f[i][j]) c.push_back(j); } for(j = i + 1;j <= u; j++) { if(f[j][i]) { v = mul(mod - f[j][i], powt(f[i][i], mod - 2)); for(auto e:c) f[j][e] = add(f[j][e], mul(f[i][e], v)); } } } u = id[55][55]; for(i = 1;i <= n; i++) { if(i == u) continue; if(f[u][i]) { v = mul(mod - f[u][i], powt(f[i][i], mod - 2)); for(j = 0;j <= n; j++) f[u][j] = add(f[u][j], mul(f[i][j], v)); } } v = powt(f[u][u], mod - 2); printf("%dn", mul(f[u][0], v)); return 0; }
|