N1(8.3) solution

Topic portal

The main idea: nn in the box at the beginningn black ballsmmm white balls,ppeach timeThe probability of p is put in a black ball, there is1 − p 1-p1The probability of p is to put a white ball in, and then randomly take a ball after the ball is placed, and ask forkkExpected number of black balls in the box after k times.

answer

It can be noticed that the number of balls after each operation is maintained at n + m n + mn+m will not change.

Ordinance ai a_iaiMeans to proceed iiThe expected number of black balls after i operations, obviouslya 0 = n a_0=na0=n

There are four cases to consider, two of which are 放一个黑球拿一个黑球and 放一个白球拿一个白球, two balls will not cause changes in the number of black so no need to consider.

The probability of putting a black ball and picking a white ball is: A = p × n + m + 1 − (ai + 1) n + m + 1 A=p\times \dfrac {n+m+1-(a_i+1) } {n+m+1}A=p×n+m+1n+m+1(ai+1), Contribution is 1 11 , because there is an extra black ball.

The probability of putting a white ball and picking a black ball is: B = (1 − p) × ain + m + 1 B=(1-p)\times \dfrac {a_i} {n+m+1}B=(1p)×n+m+1ai, The contribution is − 1 -11 because one black ball is missing.

整理得到: a i + 1 = a i + A × 1 + B × ( − 1 ) = ( p + a i ) n + m n + m + 1 a_{i+1}=a_i+A\times 1+B\times (-1)=(p+a_i)\dfrac {n+m} {n+m+1} ai+1=ai+A×1+B×(1)=(p+ai)n+m+1n+m

T = n + mn + m + 1 T = \ dfrac {n + m} {n + m + 1}T=n+m+1n+m, Naka Yu ai + 1 = T ai + p T a_ {i + 1} = Ta_i + pTai+1=T ai+p T , expand to getai = T ia 0 + p T (1 + T + T 2 +... + T i − 1) a_i=T^ia_0+pT(1+T+T^2+...+ T^{i-1})ai=Ti a0+pT(1+T+T2+...+Ti 1 ), thenO (log ⁡ k) O(\log k)O(logk ) Calculate the answer.

code show as below:

#include <cstdio>
#define mod 1000000007

int n,m,k,a,b;
int ksm(int x,int y){
    
    int re=1;for(;(y&1?re=1ll*re*x%mod:0),y;x=1ll*x*x%mod,y>>=1);return re;}
#define inv(x) ksm(x,mod-2)

int main()
{
    
    
	scanf("%d %d %d %d %d",&n,&m,&k,&a,&b);
	int p=1ll*a*inv(b)%mod,T=1ll*(n+m)*inv(n+m+1)%mod;
	printf("%d",(1ll*ksm(T,k)*n%mod+1ll*p*T%mod*(ksm(T,k)-1+mod)%mod*inv(T-1)%mod)%mod);
}

Guess you like

Origin blog.csdn.net/a_forever_dream/article/details/107790209