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. JAVA mysql数据库 配置

    mysql 版本 5.7 数据库连接版本 <!--MySql--><dependency> <groupId>mysql</groupId> <a ...

  2. java中对象和对象的引用

    1.何谓对象? 在Java中有一句比较流行的话,叫做“万物皆对象”,这是Java语言设计之初的理念之一.要理解什么是对象,需要跟类一起结合起来理解.下面这段话引自<Java编程思想>中的一 ...

  3. lintcode-15-全排列

    全排列 给定一个数字列表,返回其所有可能的排列. 注意事项 你可以假设没有重复数字. 样例 给出一个列表[1,2,3],其全排列为: [ [1,2,3], [1,3,2], [2,1,3], [2,3 ...

  4. 3dContactPointAnnotationTool开发日志(十一)

      把image也做成panel的形式了,并且放进了scrollView里,真实地显示出图像:   其它两个scrollView的content也做成自适应大小了,就是添加一项content的heig ...

  5. ZOJ 2072 K-Recursive Survival

    https://vjudge.net/contest/67836#problem/K n people numbered 1 to n around a circle, we eliminate ev ...

  6. AppDomain.CurrentDomain.AssemblyResolve

    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); 参 ...

  7. 通过设置窗体的AcceptButton属性,可以设置窗体的“接受”按钮,若此设计,则用户每次按下Enter键都相当于单击该按钮

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. OO的五大原则

    OO的五大原则是指SRP.OCP.LSP.DIP.ISP 1. SRP(Single Responsibility Principle 单一职责原则) 单一职责很容易理解,所谓单一职责,就是一个设计元 ...

  9. 【刷题】BZOJ 3513 [MUTC2013]idiots

    Description 给定n个长度分别为a_i的木棒,问随机选择3个木棒能够拼成三角形的概率. Input 第一行T(T<=100),表示数据组数. 接下来若干行描述T组数据,每组数据第一行是 ...

  10. 【刷题】洛谷 P2764 最小路径覆盖问题

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...