Valera and Number

Time Limit: 20 Sec  Memory Limit: 512 MB

Description

  

Input

  

Output

  

Sample Input

  5 3 25

Sample Output

  1.9218750000

HINT

  

Solution

  考虑运用DP。

  

Code

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long s64; const int ONE = ;
const int MOD = 1e9 + ;
const int all = ; int x, n;
double p;
double f[][][][];
double Ans;
int val, num; int get()
{
int res;char c;
while( (c=getchar())< || c> );
res=c-;
while( (c=getchar())>= && c<= )
res=res*+c-;
return res;
} void Deal_first(int n)
{
int record[], num = , x = n;
while(x)
record[++num] = x & ,
x >>= ;
int j = , pos = , val = record[pos];
for(pos = ; pos + j - <= num; j++)
if(record[pos + j] != val) break; f[][n & all][j][val] = ;
} int Get(int x)
{
int res = ;
while(x % == ) res++, x >>= ;
return res;
} int main()
{
x = get(), n = get(), p = (double)get() / ;
Deal_first(x); for(int i = ; i < n; i++)
for(int s = ; s <= all; s++)
for(int j = ; j <= ; j++)
for(int k = ; k <= ; k++)
{
val = s >> - & ;
if(val != k) num = ; else num = j + ;
f[i + ][s << & all][num][val] += f[i][s][j][k] * p; val = s == all ? (k ^ ) : k;
if(val != k && k == ) num = ; else num = j;
f[i + ][s + & all][num][val] += f[i][s][j][k] * ( - p);
} for(int s = ; s <= all; s++)
for(int j = ; j <= ; j++)
for(int k = ; k <= ; k++)
{
if(s == && k == ) val = j + ;
else if(s == && k == ) val = ;
else val = Get(s);
Ans += f[n][s][j][k] * val;
} printf("%.8lf", Ans);
}
  • Unkonwn

【Codeforces441E】Valera and Number [DP]的更多相关文章

  1. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  2. 【转】oracle数据库NUMBER数据类型

    原文:http://www.jb51.net/article/37633.htm NUMBER ( precision, scale)a)  precision表示数字中的有效位;如果没有指定prec ...

  3. 【CF245H】Queries for Number of Palindromes(回文树)

    [CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...

  4. 【BZOJ4712】洪水(动态dp)

    [BZOJ4712]洪水(动态dp) 题面 BZOJ 然而是权限题QwQ,所以粘过来算了. Description 小A走到一个山脚下,准备给自己造一个小屋.这时候,小A的朋友(op,又叫管理员)打开 ...

  5. 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树

    [BZOJ4026]dC Loves Number Theory Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源.    给 ...

  6. 【题解】Jury Compromise(链表+DP)

    [题解]Jury Compromise(链表+DP) 传送门 题目大意 给你\(n\le 200\)个元素,一个元素有两个特征值,\(c_i\)和\(d_i\),\(c,d \in [0,20]\), ...

  7. 【题解】Making The Grade(DP+结论)

    [题解]Making The Grade(DP+结论) VJ:Making the Grade HNOI-D2-T3 原题,禁赛三年. 或许是我做过的最简单的DP题了吧(一遍过是什么东西) 之前做过关 ...

  8. 【题解】NOIP2017逛公园(DP)

    [题解]NOIP2017逛公园(DP) 第一次交挂了27分...我是不是必将惨败了... 考虑这样一种做法,设\(d_i\)表示从该节点到n​节点的最短路径,\(dp(i,k)\)表示从\(i\)节点 ...

  9. 【题解】284E. Coin Troubles(dp+图论建模)

    [题解]284E. Coin Troubles(dp+图论建模) 题意就是要你跑一个完全背包,但是要求背包的方案中有个数相对大小的限制 考虑一个\(c_i<c_j\)的限制,就是一个\(c_i\ ...

随机推荐

  1. 【Docker 命令】- images命令

    docker images : 列出本地镜像. 语法 docker images [OPTIONS] [REPOSITORY[:TAG]] OPTIONS说明: -a :列出本地所有的镜像(含中间映像 ...

  2. 【Mysql】- Mysql 8.0正式版新亮点

    MySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 注意:从 MySQL 5.7 升级到 MySQL 8 ...

  3. oracle怎样查询索引的使用情况

    查询用户的索引select index_name,table_name,tablespace_name, index_type,uniqueness , status from dba_indexes ...

  4. perf 是怎么计算调用栈的时间的?

    在我真个malloc的执行过程中共调用了8次的syswrite的系统调用,其中有两次来自于__lib_write, 两次来自于__memmove_avx_unaligned,然后__memmove_a ...

  5. matlab 中try/catch语句

    try的作用是让Matlab尝试执行一些语句,执行过程中如果出错,则执行catch部分的语句,其语法: try (command1)组命令1总被执行,错误时跳出此结构 catch (command2) ...

  6. BZOJ 1196 公路修建问题(二分+最小生成树)

    题目要求求出图中的一颗生成树,使得最大的边权最小,且满足一级公路的个数>=k. 考虑二分最大边,问题就变为给出的图的生成树中,是否满足所有的边<=val,且一级公路的个数>=k. 所 ...

  7. openstack之keystone部署

    前言 openstack更新频率是挺快的,每六个月更新一次(命名是是以A-Z的方式,Austin,Bexar...Newton).博主建议大家先可一种版本研究,等某一版本研究透彻了,在去研究新的版本. ...

  8. HDU.1575 Tr A ( 矩阵快速幂)

    HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...

  9. HDU 2710

    Max Factor Time Limit: 2000/1000 MS(Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. Codeforces Round #546 (Div. 2) 题解

    Codeforces Round #546 (Div. 2) 题目链接:https://codeforces.com/contest/1136 A. Nastya Is Reading a Book ...