数学期望/马尔可夫过程

  DP/记忆化搜索

  刘汝佳老师白书上的例题……

 //UVA 11762
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*=sign;
}
const int N=1e6+;
#define debug
/******************tamplate*********************/
int prime[N],tot;
bool check[N]; void getpr(int n){
memset(check,,sizeof check);
F(i,,n){
if (!check[i]) prime[tot++]=i;
rep(j,tot){
if (i*prime[j]>n)break;
check[i*prime[j]]=;
}
}
}
bool vis[N];
double f[N];
double dp(int x){
if (x==) return 0.0;
if (vis[x]) return f[x];
vis[x]=;
double &ans = f[x];
int g=,p=; ans=;
rep(j,tot){
if (prime[j]>x) break;
p++;
if (x%prime[j]==){ g++; ans+=dp(x/prime[j]);}
}
ans=(ans+p)/g;
return ans;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("11762Race_to_1.in","r",stdin);
freopen("11762Race_to_1.out","w",stdout);
#endif
getpr(N-);
int T=getint();
F(t,,T)
printf("Case %d: %.10lf\n",t,dp(getint()));
return ;
}

【UVA】【11762】Race to 1(得到1)的更多相关文章

  1. UVA 11762 - Race to 1(概率)

    UVA 11762 - Race to 1 题意:给定一个n,每次随即选择一个n以内的质数,假设不是质因子,就保持不变,假设是的话.就把n除掉该因子,问n变成1的次数的期望值 思路:tot为总的质数. ...

  2. UVa 11762 - Race to 1

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. [uva 11762]Race to 1[概率DP]

    引用自:http://hi.baidu.com/aekdycoin/item/be20a91bb6cc3213e3f986d3,有改动 题意: 已知D, 每次从[1,D] 内的所有素数中选择一个Ni, ...

  4. UVA 11762 Race to 1(记忆化+期望)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20869 [思路] DP+期望. 设f[x]表示从x转移到1的期望操 ...

  5. UVa 11762 Race to 1 (数学期望 + 记忆化搜索)

    题意:给定一个整数 n ,然后你要把它变成 1,变换操作就是随机从小于等于 n 的素数中选一个p,如果这个数是 n 的约数,那么就可以变成 n/p,否则还是本身,问你把它变成 1 的数学期望是多少. ...

  6. UVA - 11762 - Race to 1 记忆化概率

    Dilu have learned a new thing about integers, which is - any positive integer greater than 1 can bed ...

  7. UVa 11762 (期望 DP) Race to 1

    设f(x)表示x转移到1需要的次数的期望,p(x)为不超过x的素数的个数,其中能整除x的有g(x)个 则有(1-g(x)/p(x))的概率下一步还是转移到x,剩下的情况各有1/p(x)的概率转移到x/ ...

  8. Race to 1 UVA - 11762 (记忆dp概率)

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

  9. UVa 12034 - Race(递推 + 杨辉三角)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  10. UVA 12034 Race (递推神马的)

    Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...

随机推荐

  1. 用宏定义封装LoadLibrary,方便的动态加载dll

    同学们动态加载dll的时候是不是感觉挺麻烦的,每次都::LoadLibrary,::GetProcAddress,还要typedef一堆函数.最近闲来无聊,用宏封装了一下,可以少写不少代码,用来也挺方 ...

  2. 20141201--JS Window

    一.window.screen 包含有关用户屏幕的信息. window.screen 对象在编写时可以不使用 window 这个前缀. 一些属性: screen.availWidth - 可用的屏幕宽 ...

  3. (转)RabbitMQ消息队列的小伙伴: ProtoBuf(Google Protocol Buffer)

    什么是ProtoBuf? 一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化.它很适合做数据存储或 RPC 数据交换格式.可用于通讯协议.数据存储等领域的语言无关.平台无关.可扩 ...

  4. node笔记——gulp修改静态文件的名字

    cmd小技巧: 1.换到下级或同等级目录 D: 2.换到上级目录 cd.. node 包管理器小技巧[以gulp为例] npm install --save-dev gulp gulp-concat ...

  5. 8款超酷而实用的CSS3按钮动画

    1.CSS3分享按钮动画特效 这是一款基于CSS3的社会化分享按钮,按钮非常简单,提供了分享到twitter.facebook.youtube等大型社交网站.每一个分享按钮都有个大社交网站的Logo图 ...

  6. js获取url及url参数的方法

    <script language="JavaScript" type="text/javascript"> function GetUrlParms ...

  7. android ListView_Tiger

    xml设计 <?xml version="1.0"?> -<LinearLayout tools:context=".MainActivity" ...

  8. HTML5+CSS3+JQuery打造自定义视频播放器

    来源:http://www.html5china.com/HTML5features/video/201109206_1994.html 简介HTML5的<video>标签已经被目前大多数 ...

  9. mongodb的常用操作(二)

    继续mongodb的学习: 9.mongodb条件查询 假设有user集合,里面结构如下:{ "_id" : ObjectId("52ab35d281181f853264 ...

  10. php 判断字符串在另一个字符串中位置

    $email='user@example.com';        //定义字符串$result=strstr($email,'@');         //返回子字符串echo $result; / ...