ZOJ - 2949 Coins of Luck 概率dp

题目链接:点击查看

题意:至少要制多少次筛子才能有n次正面或n次反面

题解:dp[i][j] = 1 + 0.5 * dp[i - 1][j] + 0.5 * dp[i][j - 1]

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int n,m;
double dp[1010][1010];
int main()
{
	int T;
	scanf("%d",&T);
	for(int i=1;i<=1000;i++)
	{
		dp[i][0]=0;
		for(int j=1;j<=1000;j++)
			dp[i][j]=1+0.5*dp[i][j-1]+0.5*dp[i-1][j]; 
	}
	while(T--)
	{
		scanf("%d",&n);
		printf("%.2f\n",dp[n][n]);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/mmk27_word/article/details/88844593