数学期望/马尔可夫过程

  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. chcon可实现对文件的SEAndroid安全标签的修改

    chcon可实现对文件的SEAndroid安全标签的修改 参考使用如下: chcon -u u system/app/ chcon -r object_r system/app/ chcon -t s ...

  2. iOS 最新版 CocoaPods 的安装使用

    当在开发iOS应用时,会经常使用到很多的第三方开源类库,一般的方法是直接从GitHub下载,然后拖到项目中使用,如果该开源类库不依赖其他的类库,就可以直接使用:如果该开源类库还依赖一些其他的类库,则需 ...

  3. 标识域 Identify Field

    在对象中保存DB的ID字段,以维持内存对象和DB数据Row之间的identify. 关系DB使用key来区分数据行. 而内存对象不需要这样的键.因为对象系统能够保证身份确认. 读取时没有问题,但是为了 ...

  4. RHEL(RedHat Enterprise Linux)5/6 ISO镜像下载

    本文贴出了RHEL(RedHat Enterprise Linux)发行版本中常用的服务器版本的ISO镜像文件,供大家下载学习使用,贴出的版本有RedHat Enterprise Linux(RHEL ...

  5. 实验八--uart

    一.环境 系统:ubuntu12.04 开发板:jz2440 编译器:gcc 二.说明 有空补上 三.代码 head.S @************************************** ...

  6. win7 php5.5 apache 源码安装 imagick扩展

    最近公司项目有用到php 的imagick,折腾了好长时间才把扩展装上,最主要的就是最新的不一定是最合适的,最开始一直找最新包安装,一直都不成功,经过google了好长时间,终于找到一个有用的,灵机一 ...

  7. 我们为什么要使用 href="javascript:void(0)"

    做过web前端UI的小伙伴们都知道,有时候我们在网页中会使用一些超级链接,而这些链接不用指向任何地址,只是为了配合javascript的onclick事件而存在的,当我们点击这些链接时(其实也可以看做 ...

  8. php编写简单的页面跳转功能

    不多说,直接上. //确保magic_quotes_gpc在php.ini中移开启function CheckInput($value){ //去除反斜杠 if(get_magic_quotes_gp ...

  9. IE下无法保存Cookie和Session问题

    最近在做新的Web项目时,因为一个验证码无法保存在Cookie中,或者更确切地说是IE下无法保存Cookie的问题纠结了整整一天时间,考虑了多种原因,单步调试了不下三十次,也没有结果.甚至在无奈之下改 ...

  10. ios特性访问器方法(setter和getter)

    Employee.h @interface Employee:NSObject { int _employeeNumber; NSString *_name; Employee*_supervisit ...