HihoCoder1339 Dice Possibility(概率DP+母函数)
描述
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+母函数)的更多相关文章
- HihoCoder - 1339 Dice Possibility(概率dp)
题意:求用N(1<=N<=100)个骰子掷出M(1<=M<=600)的概率 分析:直接求概率可能出现6^100次方,会爆精度.可以用一个数组dp[i][j]记录用i个骰子掷出j ...
- dice 概率论 概率DP
题目链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=459 找出公式,公式有实际意义,某种情形当 ...
- 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 ...
- hdu 4625 Dice(概率DP)
Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- HDU 4652 Dice (概率DP)
版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/36685493 D ...
- Dice (III) 概率dp
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- hihoCoder 1339 Dice Possibility(DP)
http://hihocoder.com/problemset/problem/1339 题意: 求一个骰子扔n次后最后点数相加为m的概率. 思路: f[i][j]表示扔到第i次时总值为j的概率. # ...
- Throwing Dice(概率dp)
C - Throwing Dice Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Lig ...
- HDU 4599 Dice (概率DP+数学+快速幂)
题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...
随机推荐
- Sitemesh3的使用心得
项目中用到了sitemesh3,就把使用心得记下来,至于配置之类的,官方网站都有,这里只是写下自己对它的理解,方便再次理解, sitemesh是基于过滤器的原理,拦截到符合配置文件中配置的路径,然后会 ...
- Bootstrap学习-菜单-按钮-导航
1.下拉菜单(基本用法) 在使用Bootstrap框架的下拉菜单时,必须调用Bootstrap框架提供的bootstrap.js文件.当然,如果你使用的是未编译版本,在js文件夹下你能找到一个名为“d ...
- IDEA main方法自动补全(转发:http://blog.csdn.net/zjx86320/article/details/52684601)
最近刚从Eclipse转到IDEA,各种学习丫,IDEA里的main方法是不能自动补齐的,肿么办呢? 1.首先,点击File-->Settings-->Editor-->Live T ...
- sublime 添加 颜色插件 colorcoder
高亮所有变量,因此可以极大的简化代码定位.尤其是对那些有阅读障碍的程序员非常有帮助.
- linux awk数组相关操作介绍
用awk进行文本处理,少不了就是它的数组处理.那么awk数组有那些特点,一般常见运算又会怎么样呢.我们先看下以下的一些介绍,结合样例我们会解说下它的不同之处.在 awk 中数组叫做关联数组(assoc ...
- Linuxshell资料汇总
1.判断文件是否存在 https://www.cnblogs.com/platero/p/4021561.html 2.日期赋值 https://www.cnblogs.com/lonelywolfm ...
- sql的执行过程
from ===> where ===> group by ===> select ===>order by 这个执行流程 很重要~~
- LINQ 学习路程 -- 查询例子
IList<Student> studentList = new List<Student>() { , StudentName = , StandardID = } , , ...
- C语言中的位操作(15)--确定log10(N)的整数部分
本篇文章介绍一个整数的以10为底的对数的整数部分,即对于整数N,求log10(N)整数部分 方法一 : unsigned int v; //32位非0整数 int r; // r保存结果 int t; ...
- ibatis的resultClass与resultMap 的区别
ibatis的resultClass与resultMap还是有很大的区别.以下是我碰到的一个问题. 配置文件写法如下: 1 sqlMap2 typeAlias alias="notice&q ...