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 ...
随机推荐
- C语言基础知识【指针】
2017年7月11日18:33:41C指针 该看地址:http://www.runoob.com/cprogramming/c-pointers.html1.学习 C 语言的指针既简单又有趣.通过指 ...
- POJ1942
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 24236 Accepted: 6006 ...
- eclipse里面用svn关联项目
eclipse里面共享项目经常会用到svn或者git插件 关联项目的步骤如下: 如果 点击finish会遇到卡住问题的话,不要着急,我们需要设置svn的client设置: 如果设置了之后还是很卡的话, ...
- PAT 1063. 计算谱半径(20)
在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界.换言之,对于给定的n个复数空间的特征值{a1+b1i, ..., an+bni},它们的模为实部与虚部的平方和的开方,而“谱半径”就是最大模. ...
- 全栈JavaScript之路( 二十四 )DOM2、DOM3, 不涉及XML命名空间的扩展
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/hatmore/article/details/37658167 (一)DocumentType 类型 ...
- nc传文件
nc传文件 先启动接收方 nc -l -p 9999 > index.lua 后启动发送方 nc 192.168.1.1 9999 < index.lua
- VMware Integrated OpenStack (VIO)简介
VMware Integrated OpenStack是一款由VMware提供支持的OpenStack发行版软件,用于帮助IT在现有的VMware基础架构之上更加轻松地运行基于生产级OpenStack ...
- JDK线程池的实现
线程池 接口Executor 该接口只有一个方法,JDK解释如下 执行已提交的Runnable 任务的对象.此接口提供一种将任务提交与每个任务将如何运行的机制(包括线程使用的细节.调度等)分离开来的方 ...
- 扩展 Yii2 自带的日志组件
<?php /** * author : forecho <caizhenghai@gmail.com> * createTime : 2015/12/22 18:13 * desc ...
- 【leetcode】Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...