标签:main hat 单点 get 0ms limit col equal names
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.
2 10
8.33
#include<cstdio> #include<cstdlib> #include<iostream> using namespace std; double ans; double a[1010],b[1010]; int n,m; void getdp() { for(int i=1;i<=6;i++) a[i]=1; for(int i=2;i<=n;i++){ for(int j=m;j>=1;j--) for(int k=1;k<=6;k++) if(j-k>0) b[j]+=a[j-k]; for(int j=1;j<=m;j++){ a[j]=b[j]; b[j]=0; } } } int main() { scanf("%d%d",&n,&m); getdp(); ans=1.0*a[m]; for(int i=1;i<=n;i++){ ans/=6.0; } ans*=100; printf("%.2lf\n",ans); return 0; }
#include<cstdio> #include<cstdlib> #include<iostream> using namespace std; using namespace std; double d[101][601]; int main() { int n,m; scanf("%d%d",&n,&m); memset(d,0,sizeof d); d[0][0]=1; for(int i=1;i<=n;i++) { for(int k=1;k<=6;k++) { for(int j=m;j>=k;j--)d[i][j]+=d[i-1][j-k]/6; } } printf("%0.2lf\n",d[n][m]*100); return 0; }
HihoCoder1339 Dice Possibility(概率DP+母函数)
标签:main hat 单点 get 0ms limit col equal names
原文地址:http://www.cnblogs.com/hua-dong/p/7955709.html