数学期望/马尔可夫过程

  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. Linux 文件及文件夹权限

    普及 linux 基础知识,Linux 文件及文件夹权限,不要动不动就 777 权限.网上教程过于复杂啰嗦,简单总结如下...一.查看 Linux 文件权限 ls -l (通用)ll (Ubuntu适 ...

  2. Mysql按时间段分组查询来统计会员的个数

    1.使用case when方法(不建议使用)-  代码如下 复制代码 SELECT    COUNT(DISTINCT user_id) user_count,    CASE    WHEN cre ...

  3. 零基础Android学习笔记-03 窗口间的数据传递

    1.通过全局变量来传递. 新建一个全局的类继承于Application package com.example.helloworld; import android.app.Application; ...

  4. iOS中关于.pch的新建与配置问题

    以前版本的Xcode新建一个项目都会自动生成.pch,这个文件的好处是,里面添加的东西会自动添加到每个类中,也就是说我们可以把要用的宏定义,和多个头文件等放到.pch中,这样我们就不需要重复的在每个类 ...

  5. 依赖映射 Dependent Mapping

    让一个类为其子类(泛意上的)执行DB映射 一些对象肯定会出现在另一对象的上下文中. 此时,使用另一对象的Mapper来执行第一个对象的映射,来简化映射过程. 运行机制 在DB持久化时,依赖者类依赖于所 ...

  6. POJ 2837 Til the Cows Come Home

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45515   Accepted: 15434 Description Bes ...

  7. 使用 Time Machine 恢复 .ssh等隐藏文件夹

    重装MAC系统后,要恢复.ssh等文件夹内容,而其在“Finder”中又是默认隐藏的,这时我们可以先在“Finder”中使用“前往文件夹功能…”进入指定文件夹,然后再进入“Time Machine”进 ...

  8. js设计模式(10)---观察者模式

    0.前言 最近好多烦心事,由于自己的拖延懒惰造成事情堆积如山,看来最近得勤快些了,不然真的会死的很惨. 1.观察者模式是什么 又叫做发布者订阅者模式(publish/Subscribe),用来确定对象 ...

  9. winform Config文件操作

    using System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Config ...

  10. CF 148A Insomnia cure

    题目链接:传送门 题目大意:就是给四个数,和一个d,问1-d中有多少个数字不是那四个数的倍数; 这道题的d数据很小直接暴力可以过: 暴力代码:时间复杂度O(1): #include<stdio. ...