LightOJ 1038 Race to 1 Again(概率dp+期望)
https://vjudge.net/problem/LightOJ-1038
题意:
给出一个数n,每次选择n的一个约数m,n=n/m,直到n=1,求次数的期望。
思路:
d【i】表示将i这个数变成1的次数期望。
现在对于D来说,d【D】=1/cnt*{(d【D/1】+1)+(d【D/x1】+1)+(d【D/x2】+1)....+(D【D/D】+1)}
化简得 d【D】=1/(cnt-1)*(d【D/1】+d【D/x1】+...d【D/D】+cnt)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + ; int n;
double d[maxn]; void init()
{
d[]=;
for(int i=;i<=1e5;i++)
{
d[i]=;
int cnt=;
for(int j=;j*j<=i;j++)
{
if(i%j==)
{
if(i/j!=j)
{
cnt+=;
d[i]+=d[j]+d[i/j]+;
}
else
{
cnt+=;
d[i]+=d[j]+;
}
}
}
d[i]/=(1.0*(cnt-));
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
int kase=;
scanf("%d",&T);
init();
while(T--)
{
scanf("%d",&n);
printf("Case %d: %.7f\n",++kase,d[n]);
}
return ;
}
LightOJ 1038 Race to 1 Again(概率dp+期望)的更多相关文章
- Lightoj 1038 - Race to 1 Again (概率DP)
题目链接: Lightoj 1038 - Race to 1 Again 题目描述: 给出一个数D,每次可以选择数D的一个因子,用数D除上这个因子得到一个新的数D,为数D变为1的操作次数的期望为多少 ...
- LightOJ 1038 Race to 1 Again (概率DP,记忆化搜索)
题意:给定一个数 n,然后每次除以他的一个因数,如果除到1则结束,问期望是多少. 析:概率DP,可以用记忆公搜索来做,dp[i] = 1/m*sum(dp[j] + 1) + 1/m * (dp[i] ...
- 2017 ICPC Asia Urumqi A.coins (概率DP + 期望)
题目链接:Coins Description Alice and Bob are playing a simple game. They line up a row of nn identical c ...
- luogu P6835 概率DP 期望
luogu P6835 概率DP 期望 洛谷 P6835 原题链接 题意 n + 1个节点,第i个节点都有指向i + 1的一条单向路,现在给他们添加m条边,每条边都从一个节点指向小于等于自己的一个节点 ...
- LightOJ - 1038 Race to 1 Again —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1038 1038 - Race to 1 Again PDF (English) Statistics Foru ...
- LightOJ 1151 Snakes and Ladders(概率DP + 高斯消元)
题意:1~100的格子,有n个传送阵,一个把进入i的人瞬间传送到tp[i](可能传送到前面,也可能是后面),已知传送阵终点不会有另一个传送阵,1和100都不会有传送阵.每次走都需要掷一次骰子(1~6且 ...
- 概率dp+期望dp 题目列表(一)
表示对概率和期望还不是很清楚定义. 目前暂时只知道概率正推,期望逆推,然后概率*某个数值=期望. 为什么期望是逆推的,例如你求到某一个点的概率我们可以求得,然后我们只要运用dp从1~n每次都加下去就好 ...
- LightOJ 1038 - Race to 1 Again(期望+DP)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1038 题意是:给你一个N (1 ≤ N ≤ 105) 每次N都随机选一个因子d,然后让 ...
- Lightoj 1038 - Race to 1 Again【期望+dp】
题目:戳这里 题意:一个数字n不断迭代地除以自身的因子得到1.求这个过程中操作除法次数的期望. 解题思路: 求概率基本都是从一个最基础的状态开始延伸推出公式,得出答案.因为每个数都有个共同的最终状态1 ...
随机推荐
- 微信小游戏 egret.getDefinitionByName获取不到
使用getDefinitionByName获取类定义 输出为null,获取不了 增加window["LoadingUI"] = LoadingUI 获取成功 总结: 这样无论是游戏 ...
- 【BZOJ4428】[Nwerc2015]Debugging调试 记忆化搜索+分块
[BZOJ4428][Nwerc2015]Debugging调试 Description 你看中的调试器将不会在这件事上帮助你.有代码可以通过多种方式在调试与正式发布的间隙发生不同的行为,当出现这种情 ...
- Gallery 里面怎么设置ImageView的OnClick事件
Gallery g=this.findViewById(R.id.gallery); g.setOnItemClickListener(new OnItemClickListener(){ @Over ...
- mysql的TIMESTAMPDIFF
SELECT (TIMESTAMPDIFF(MINUTE, STR_to_date('2018-8-30 12:15:52', '%Y-%m-%d %H:%i:%s') , STR_to_date(' ...
- R语言NULL、NA、0
0是假 NULL.NA无法辨认真假 除了以上3个其他的都是真 > if (NULL) print("OK") else print("Error") Er ...
- POI各Jar包的作用(转)
目前POI的最新发布版本是3.10_FINAL.该版本保护的jar包有: Maven artifactId Prerequisites JAR poi commons-logging, commons ...
- sublime3095-注册码下载安装
链接:http://pan.baidu.com/s/1hqejFKS 下载地址:下载 提取密码:egh5 ----- BEGIN LICENSE ----- Andrew Weber Single U ...
- Jquery Uploadify使用参数详解
开始上传 $('#uploadify_1').uploadifyUpload(); 1 uploader uploadify.swf文件的相对路径,该swf文件是一个带有文字BROWSE的按钮,点击 ...
- HDU 6016 Count the Sheep
Count the Sheep Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Code Forces 652C Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...