CF963E.Circles of Waiting

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A chip was placed on a field with coordinate system onto point (0, 0).

Every second the chip moves randomly. If the chip is currently at a point (x, y), after a second it moves to the point (x - 1, y) with probability _p_1, to the point (x, y - 1) with probability _p_2, to the point (x + 1, y) with probability _p_3 and to the point (x, y + 1) with probability _p_4. It's guaranteed that _p_1 + _p_2 + _p_3 + _p_4 = 1. The moves are independent.

Find out the expected time after which chip will move away from origin at a distance greater than R (i.e. will be satisfied).

一枚芯片被放置在带有坐标系的平面上的点 (0, 0)(0,\,0) 处。

每一秒,该芯片随机移动一次。若芯片当前位于点 (x, y)(x,\,y),则经过一秒后,它将以概率 p1p_1 移动到点 (x−1, y)(x-1,\,y),以概率 p2p_2 移动到点 (x, y−1)(x,\,y-1),以概率 p3p_3 移动到点 (x+1, y)(x+1,\,y),以概率 p4p_4 移动到点 (x, y+1)(x,\,y+1)。已知 p1+p2+p3+p4=1p_1 + p_2 + p_3 + p_4 = 1。各次移动相互独立。

求芯片首次离开原点距离超过 RR(即满足 )的期望时间。

输入格式

First line contains five integers R, _a_1, _a_2, _a_3 and _a_4 (0 ≤ R ≤ 50, 1 ≤ _a_1, _a_2, _a_3, _a_4 ≤ 1000).

Probabilities p__i can be calculated using formula .

第一行包含五个整数 RR、a1a_1、a2a_2、a3a_3 和 a4a_4(其中 0≤R≤500 \leq R \leq 50,1≤a1,a2,a3,a4≤10001 \leq a_1, a_2, a_3, a_4 \leq 1000)。

概率 pip_i 可通过公式 计算。

输出格式

It can be shown that answer for this problem is always a rational number of form , where .

Print P·Q - 1 modulo 109 + 7.

可以证明,本题的答案总是一个形如 的有理数,其中 。

请输出 $ P \cdot Q^{-1} \bmod (10^9 + 7) $。

输入输出样例

  • 输入#1

    0 1 1 1 1

    输出#1

    1
  • 输入#2

    1 1 1 1 1

    输出#2

    666666674
  • 输入#3

    1 1 2 1 2

    输出#3

    538461545

说明/提示

In the first example initially the chip is located at a distance 0 from origin. In one second chip will move to distance 1 is some direction, so distance to origin will become 1.

Answers to the second and the third tests: and .

在第一个例子中,芯片初始时位于距原点距离为 0 的位置。一秒后,芯片将向某个方向移动至距原点距离为 1 的位置,因此其到原点的距离变为 1。

第二和第三个测试用例的答案分别为: 和 。

输入解题思路,AI测评打分。不知道怎么写?

首页