【Codeforces441E】Valera and Number [DP]
Valera and Number
Time Limit: 20 Sec Memory Limit: 512 MB
Description

Input

Output

Sample Input
Sample Output
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]的更多相关文章
- 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)
[LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【转】oracle数据库NUMBER数据类型
原文:http://www.jb51.net/article/37633.htm NUMBER ( precision, scale)a) precision表示数字中的有效位;如果没有指定prec ...
- 【CF245H】Queries for Number of Palindromes(回文树)
[CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...
- 【BZOJ4712】洪水(动态dp)
[BZOJ4712]洪水(动态dp) 题面 BZOJ 然而是权限题QwQ,所以粘过来算了. Description 小A走到一个山脚下,准备给自己造一个小屋.这时候,小A的朋友(op,又叫管理员)打开 ...
- 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树
[BZOJ4026]dC Loves Number Theory Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给 ...
- 【题解】Jury Compromise(链表+DP)
[题解]Jury Compromise(链表+DP) 传送门 题目大意 给你\(n\le 200\)个元素,一个元素有两个特征值,\(c_i\)和\(d_i\),\(c,d \in [0,20]\), ...
- 【题解】Making The Grade(DP+结论)
[题解]Making The Grade(DP+结论) VJ:Making the Grade HNOI-D2-T3 原题,禁赛三年. 或许是我做过的最简单的DP题了吧(一遍过是什么东西) 之前做过关 ...
- 【题解】NOIP2017逛公园(DP)
[题解]NOIP2017逛公园(DP) 第一次交挂了27分...我是不是必将惨败了... 考虑这样一种做法,设\(d_i\)表示从该节点到n节点的最短路径,\(dp(i,k)\)表示从\(i\)节点 ...
- 【题解】284E. Coin Troubles(dp+图论建模)
[题解]284E. Coin Troubles(dp+图论建模) 题意就是要你跑一个完全背包,但是要求背包的方案中有个数相对大小的限制 考虑一个\(c_i<c_j\)的限制,就是一个\(c_i\ ...
随机推荐
- 爬取CVPR 2018过程中遇到的坑
爬取 CVPR 2018 过程中遇到的坑 使用语言及模块 语言: Python 3.6.6 模块: re requests lxml bs4 过程 一开始都挺顺利的,先获取到所有文章的链接再逐个爬取获 ...
- Swift-可选值(Optional)讲解
前提:Swift中有规定:对象中的任何属性在创建时,都必须要有明确的初始化值 1.定义可选类型 方式一:常规方式(不常用) var name : Optional<String> = ni ...
- 3ds Max学习日记(六)
到了周六就不想再忙实验室的活了,于是玩了一下3ds max,第5和第6章每章都只有4个视频,于是就一起弄完了,什么网格建模,曲面建模啥的,nurbs啥的. 附上今日的劳动成果: 叉子(用长方体 ...
- PokeCats开发者日志(九)
现在是PokeCats游戏开发的第十五天的中午,总算过了规范性检查这一关. 但愿能过吧.
- git初始化之git config
git初始化之git config 1. 下面的命令将修改/home/[username]/.gitconfig文件,也就是说下面的配置只对每一个ssh的用户可见,所以每个人都需要做. 提 ...
- 【Docker 命令】- images命令
docker images : 列出本地镜像. 语法 docker images [OPTIONS] [REPOSITORY[:TAG]] OPTIONS说明: -a :列出本地所有的镜像(含中间映像 ...
- WebKit 源码分析 -- loader
原文地址: http://peirenlei.iteye.com/blog/1718569 摘要:本文介绍 WebCore 中 Loader 模块是如何加载资源的,分主资源和派生资源分析 loader ...
- MongoDB、ElasticSearch、Redis、HBase这四种热门数据库的优缺点及应用场景
MongoDB MongoDB是当今最火爆的NoSQL数据库.MongoDB最早在09年发布,算得上是早期大数据时代的数据库代表作了.随着MongoDB的火爆,研发MongoDB的团队还专门成立了Mo ...
- IE BHO的IObjectWithSite接口
Internet Explorer的BHO的对象必须实现IObjectWithSite接口.该接口是IE用来对插件进行管理和通讯的一个接口,其有SetSite和GetSite两个方法,当IE加载和卸载 ...
- window service 创建
1:vs中创建一个 window servece 2.右键 添加安装程序 3.更改属性视图中的Account属性为LocalService(本地服务) 更改ServiceName为你自己的服务名称 ...