#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(a, n) for(int i=a; i<=n; i++)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int primes[maxn], vis[maxn];
double f[maxn];
int ans = ;
void init()
{
mem(vis, );
for(int i=; i<maxn; i++)
{
if(vis[i]) continue;
primes[ans++] = i;
for(LL j=(LL)i*i; j<maxn; j+=i)
vis[j] = ;
}
} double dp(int x){
if (x==) return 0.0;
if (f[x]) return f[x];
// vis[x]=1;
int g=,p=;
double res=;
for(int j=; j<ans && primes[j] <= x; j++){
if (primes[j]>x) break;
p++;
if (x%primes[j]==){ g++; res+=dp(x/primes[j]);}
}
f[x] = (res+p)/(double)g;
return f[x];
}
int main()
{
init();
int T, kase = ;
mem(f, 0.0);
cin>> T;
while(T--)
{
int n;
cin>> n;
double ans = dp(n);
printf("Case %d: %.10f\n", ++kase, ans);
} return ;
}

Race to 1 UVA - 11762 (记忆dp概率)的更多相关文章

  1. 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/ ...

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

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

  3. UVA 11427 Expect the Expected(DP+概率)

    链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...

  4. tyvj P1864 [Poetize I]守卫者的挑战(DP+概率)

    P1864 [Poetize I]守卫者的挑战 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜 ...

  5. UVA.10192 Vacation (DP LCS)

    UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...

  6. UVA.10130 SuperSale (DP 01背包)

    UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...

  7. [LnOI2019]加特林轮盘赌(DP,概率期望)

    [LnOI2019]加特林轮盘赌(DP,概率期望) 题目链接 题解: 首先特判掉\(p=0/1\)的情况... 先考虑如果\(k=1\)怎么做到\(n^2\)的时间复杂度 设\(f[i]\)表示有\( ...

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

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

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

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

随机推荐

  1. Nginx入门篇(七)之Nginx+keepalived高可用集群

    一.keepalived介绍 keepalived软件最开始是转为负载均衡软件LVS而设计,用来管理和监控LVS集群系统中各个服务节点的状态,后来又加入了可实现高可用的VRRP功能.所以Keepali ...

  2. WPF DrawingContext Pen

    <Window x:Class="WPFDrawing.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...

  3. JS基础,课堂作业,相亲问答

    相亲问答 <script> var a = prompt("你有房子么?"); var b = prompt("你有钱么?"); var c = p ...

  4. Python小白学习之基础知识(个人笔记)

    介绍while else的使用,这个不常用 格式化输出 while esle ,当循环内有break语句时,不执行else语句,当没有break语句时,执行完while循环,然后执行else下面的语句 ...

  5. 安装文件报错error while loading shared libraries: libssl.so.6

    http://www.openssl.org/source/  这里下载http://www.openssl.org/source/openssl-1.0.0r.tar.gz 安装命令为:tar -z ...

  6. Linux 安装Redis<集群版>(使用Mac远程访问)

    阅读本文需要先阅读安装Redis<准备> 一 架构细节 所有的redis节点彼此互联(PING-PONG机制) 内部使用二进制协议优化传输速度和带宽 节点的fail是通过集群中超过半数的节 ...

  7. 使用HackRF和外部时钟实现GPS欺骗实验

    本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...

  8. 苹果没放弃手写笔 这样的iPad你想要吗?

    12 月 31 日,美国专利与商标局(The U.S. Patent and Trademark Office)当地时间周四批准了一项来自苹果的专利申请,该专利主要描述的是一种可以通过陀螺仪.无线通讯 ...

  9. Centos7 Zabbix监控部署

    Zabbix监控 官方文档 https://www.zabbix.com/documentation/3.4/zh/manual https://www.zabbix.com/documentatio ...

  10. 团队介绍&学长采访

    1. 团队介绍 刘畅 博客园ID:森高Slontia 身份:PM 个人介绍: 弹丸粉 || 小说创作爱好者 || 撸猫狂魔 我绝对不知道,我一个写代码的怎么就当PM去了? 张安澜 博客园ID:Mins ...