时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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[],b[];
int n,m;
void getdp()
{
for(int i=;i<=;i++) a[i]=;
for(int i=;i<=n;i++){
for(int j=m;j>=;j--)
for(int k=;k<=;k++)
if(j-k>) b[j]+=a[j-k];
for(int j=;j<=m;j++){
a[j]=b[j];
b[j]=;
}
}
}
int main()
{
scanf("%d%d",&n,&m);
getdp();
ans=1.0*a[m];
for(int i=;i<=n;i++){
ans/=6.0;
}
ans*=;
printf("%.2lf\n",ans);
return ;
}

常规DP写法:

#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
using namespace std;
double d[][];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
memset(d,,sizeof d);
d[][]=;
for(int i=;i<=n;i++)
{
for(int k=;k<=;k++)
{
for(int j=m;j>=k;j--)d[i][j]+=d[i-][j-k]/;
}
}
printf("%0.2lf\n",d[n][m]*);
return ;
}

HihoCoder1339 Dice Possibility(概率DP+母函数)的更多相关文章

  1. HihoCoder - 1339 Dice Possibility(概率dp)

    题意:求用N(1<=N<=100)个骰子掷出M(1<=M<=600)的概率 分析:直接求概率可能出现6^100次方,会爆精度.可以用一个数组dp[i][j]记录用i个骰子掷出j ...

  2. dice 概率论 概率DP

    题目链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=459 找出公式,公式有实际意义,某种情形当 ...

  3. hdu 4586 Play the Dice(概率dp)

    Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...

  4. hdu 4625 Dice(概率DP)

    Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  5. HDU 4652 Dice (概率DP)

    版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/36685493 D ...

  6. Dice (III) 概率dp

    #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...

  7. hihoCoder 1339 Dice Possibility(DP)

    http://hihocoder.com/problemset/problem/1339 题意: 求一个骰子扔n次后最后点数相加为m的概率. 思路: f[i][j]表示扔到第i次时总值为j的概率. # ...

  8. Throwing Dice(概率dp)

    C - Throwing Dice Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Lig ...

  9. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

随机推荐

  1. React-Native在gitHub下载的Demo不能运行问题!!!

    1.目前找到的最可行的运行React-Native Demo的解决方案 请参考:http://blog.csdn.net/shubinniu/article/details/52873250 2.检查 ...

  2. Inside a super fast CSS engine: Quantum CSS (aka Stylo)

    https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/?utm_source=d ...

  3. zabbix 主机组管理

    分组的目的是将同一属性的主机归类,主机组中可以包含主机,也可以包含模板 建议:同一属性的主机或者模板,尽量归纳到分组中方便以后管理.分组原则如下: 以地理位置进行划分 以业务划分 以机器用途划分 以系 ...

  4. IE11 for Windows 7 Enterprise With SP1 故障

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jaminwm/article/details/29592027 这个故障非常诡异,卸载IE11也没实 ...

  5. MyEclipse2014新增bug,尝鲜的朋友需注意NotFoundException: org.springframework.web.context.ContextLoaderListener

    事实上标题后面加上这个异常信息并不合适,可是为了方便和我遇到相同问题的童鞋搜到这篇文章.我不得不这样写啦. 这个异常和你的程序没有关系,假设你没有忘记增加spring Jar包的话,这是fucking ...

  6. JavaScript中的this用法

    最近看了许多JavaScript源代码,发现this经常出现,于是对this这个非常特殊的关键词标识符进行总结. 题外话: 1.当函数被调用时,一个activation record[过程活动记录 - ...

  7. python基础6 ----python函数

    python函数 一.函数的参数 1.函数的参数从调用的角度来讲可以分为形式参数和实际参数,也可叫形参和实参.     形参:变量只有在被调用时才分配内存单元,在调用结束时,即刻释放所分配的内存单元. ...

  8. Redis持久化——RDB(一)

    核心知识点: 1.RDB:将当前数据生成快照保存到硬盘 2.手动触发 save:会阻塞Redis服务器直到RDB完成. bgsave:执行fork创建子进程,由子进程负责RDB操作,阻塞只发生在for ...

  9. Kattis - friday 【数学】

    题意 每一年的第一天 都是星期天 然后 给出 一年的总天数 和 总月数 以及 每个月 的总天数 求出 有多少个星期五 是当月的13号 思路 对于 每个月 只要判断 当月的13号 是不是 星期五 就可以 ...

  10. 从性能角度分析一下String,List,Map

    使用String.subString()方法的时候注意内存溢出的问题 public static void testH() { List<String> strings = new Arr ...