SP1026 FAVDICE - Favorite Dice

1.题目含义:

掷一个n面的骰子,问每一面都被掷到的次数期望是多少。

2.思路(by——洛谷):

概率DP—— SP1026 FAVDICE - Favorite Dice(洛谷)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#define mxn 1010
int n;
double dp[mxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		dp[n]=0.0;
		for(int i=n-1;i>=0;--i)
			dp[i]=dp[i+1]+(double)n/(n-i);
		printf("%.2lf\n",dp[0]);
	}
	return 0;
}

 

相关文章:

  • 2021-10-28
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-09-14
  • 2021-12-10
猜你喜欢
  • 2022-02-10
  • 2021-11-07
  • 2021-10-23
  • 2021-07-27
  • 2021-12-01
相关资源
相似解决方案