时间限制:
10000ms
单点时限:
1000ms
内存限制:
256MB
-
2 10
样例输出
-
8.33
描述
What is possibility of rolling N dice and the sum of the numbers equals to M?
输入
Two integers N and M. (1 ≤ N ≤ 100, 1 ≤ M ≤ 600)
输出
Output the possibility in percentage with 2 decimal places.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
double tmp;
double dp[101][610];
double dfs(int pos,int last) {
if(dp[pos][last]!=-1) return dp[pos][last];
int s=max(last-pos*6,1);
int e=min(last-pos*1,6);
double ans=0;
for(int i=s;i<=e;i++) {
double tmp_ans=dfs(pos-1,last-i);
if(tmp_ans!=0) ans+=tmp_ans*tmp;
}
dp[pos][last]=ans;
return dp[pos][last];
}
int main()
{
cin>>n>>m;
tmp=1.0/6;
for(int i=0;i<n;i++) {
for(int j=1;j<=600;j++) {
dp[i][j]=-1;
}
}
for(int i=1;i<=6;i++) {
dp[0][i]=tmp;
}
dfs(n-1,m);
if(dp[n-1][m]==-1) printf("0.00\n");
else printf("%.2f\n",dp[n-1][m]*100);
return 0;
}