时间限制: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. Python装饰器 计时器记录方法执行性能

    import time def timeit(func): def wrapper(): start = time.clock() func() end =time.clock() print 'us ...

  2. EasyPlayer RTSP播放器OCX RegSvr32注册报错,DllRegisterServer调用失败,错误代码为0x80040200 解决方法

    问题描述 模块"EasyPlayer-RTSPWebActiveX.ocx" 已加载,但对DLLRegisterServer调用失败,错误代码为0x80040200. 解决方法 是 ...

  3. Every norm is a convex function

    https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Convex_function.html Every  ...

  4. C++, Java和C#的编译、链接过程解析

    总是感觉java是解释性语言,转载下一篇感觉写的容易理解的文章 转自 http://www.cnblogs.com/rush/p/3155665.html 1.1.1 摘要 我们知道计算机不能直接理解 ...

  5. c++操作flash

    c++操作falsh,忘了原文在哪了,自己尝试了,直接贴代码 // SDK版本 //////////////////////////////////////////////////////////// ...

  6. Python整型int、浮点float常用方法

    #!/usr/bin/env python # -*- coding:utf-8 -*- # Python整型int.浮点float # abs(x) # 返回数字的绝对值,如abs(-10) 返回 ...

  7. CentOS 7 巨大变动之 systemd 取代 SysV的Init

    1 systemd是什么 首先systmed是一个用户空间的程序,属于应用程序,不属于Linux内核范畴,Linux内核的主要特征在所有发行版中是统一的,厂商可以自由改变的是用户空间的应用程序.   ...

  8. ggplot2绘图系统

    ggplot2包实现了一个在R中基于全面一致的语法创建图形时的系统 .在ggplot2中,图是采用串联起来(+)号函数创建的.详细内容参见<ggplot2:数据分析与图形艺术>,这里只简要 ...

  9. 更改node版本

    npm install -g n n stable 或 n v4.5.0

  10. vim终端配色(非gui版本)——Monokai

    啥也别说,先上图. 具体配置: 1. 将molokai.vim文件(下面贴出)放到 ~/.vim/colors 目录下,如没有此文件夹需自行创建. 提示:~ 代表用户主目录,如我的用户名是 akaed ...