Home >Web Front-end >HTML Tutorial >Codeforces Round #105 (Div. 2) D Probability DP_html/css_WEB-ITnose

Codeforces Round #105 (Div. 2) D Probability DP_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:54:011135browse

Question

Well, I figured it out after thinking about it for a long time. The meaning of the question is a bit vague. There are w white items and b black items. A and B take turns to draw, A starts first. Whoever draws white first wins. If no white is drawn in the end, B wins. The drawn items will not be put back. After B draws, one additional item will be lost. What is the probability of A winning? 🎜>

Still takes the target state as the boundary, and the probability required from the current state to the target state is the equation

dp[i][j] means that when it is the current turn for A to draw, there are i What is the probability of winning j white and black A

Then there are four possible transfers

1: A draws the white one, then it wins directly, and there is no need to continue. So it is not related to other state equations

2: A draws black, and next time B draws white, then A loses. If he loses, it is over. It has no impact on the answer we require below, so no matter This one

3: A drew black, and the next time B drew black, and the missing one was white, which is dp[i - 1][j - 2], because this did not produce an absolute The state of winning or losing, so it will be helpful for the transfer and recursion of the following equation, so you need to contact

4: A draws black, and the next time B draws black, and the lost one is black, which is dp [i][j - 3], this does not produce absolute winning or losing, so you still need to contact


Then the boundary dp[0][0] = 0, because When it’s A’s turn, there is nothing left to draw, which means that all are drawn. At this time, according to the question conditions, B wins

and dp[i][0] When it’s A’s turn to draw, the black ones have already been drawn. There is no more, then A can only draw the white one, so he will definitely win

and dp[0][j] When it is A's turn, there is no more white one, so he will lose


double dp[1000 + 55][1000 + 55];int w,b;void init() {	memset(dp,0.00,sizeof(dp));}bool input() {	while(cin>>w>>b) {		return false;	}	return true;}void cal() {	dp[0][0] = 0.00;	for(int i=1;i<=w;i++)dp[i][0] = 1.00;	for(int j=1;j<=b;j++)dp[0][j] = 0.00;	for(int i=1;i<=w;i++) {		for(int j=1;j<=b;j++) {			dp[i][j] = (i * 1.0)/(i + j)*1.0;			if(j >= 2) dp[i][j] += dp[i - 1][j - 2] * (j * 1.0)/(i + j) * (j - 1) * 1.0/(i + j - 1) * (i * 1.0)/(i + j - 2);			if(j >= 3) dp[i][j] += dp[i][j - 3] * (j * 1.0)/(i + j) * (j - 1)*1.0/(i + j - 1) * (j - 2) * 1.0/(i + j - 2);		}	}	printf("%.10lf\n",dp[w][b]);}void output() {}int main() {	while(true) {		init();		if(input())return 0;		cal();		output();	}	return 0;}




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn