【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\ ...
随机推荐
- c#基类继承
[ 塔 · 第 三 条 约 定 ] 编写一个多边形作为基类(成员:定点数)抽象方法(子类实现):体积.边长 正三角形类:成员 边长 长方形类:成员 长宽 using System; using Sys ...
- iOS开发跳转指定页面
for (UIViewController *VC in self.navigationController.viewControllers) { if ([VC isKindOfClass:[Car ...
- AjaxPro怎么用
AjaxPro是首家支持以各种方式通过javascript访问服务端.net的免费库,类似于SAJAX.它能把Javascript请求发送到.NET方法,服务端传回给Javascript,甚至包括串行 ...
- 微信小程序 功能函数 计时器
let lovetime = setInterval(function () { let str = '(' + n + ')' + '重新获取' that.setData({ getText2: s ...
- 安装django 提示ImportError: No module named setuptools
安装django前要先安装setuptools 先安装一些必要的包,否则会报错:Python build finished, but the necessary bits to build these ...
- 提升MyEclipse运行速度
修改MyEclipse.ini文件中的,将-vmargs后面的参数修改为 -Xms256m -Xmx768m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:Max ...
- [计算机网络] DNS何时使用TCP协议,何时使用UDP协议
DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议. 先简单介绍下TCP与UDP. ...
- InstallShield Limited Edition for Visual Studio 国内注册时国家无下拉框解决方法
注册地址:http://learn.flexerasoftware.com/content/IS-EVAL-InstallShield-Limited-Edition-Visual-Studio 火狐 ...
- MVC绕过登陆界面验证时HttpContext.Current.User.Identity.Name取值为空问题解决方法
Global.asax界面添加如下方法: void FormsAuthentication_Authenticate(object sender, FormsAuthenticationEventAr ...
- VisualVM使用方法
VisualVM 简介 VisualVM 是一个工具,它提供了一个可视界面,用于查看 Java 虚拟机 (Java Virtual Machine, JVM) 上运行的基于 Java 技术的应用程序( ...