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

  1. #include<iostream>
  2. #include<string>
  3. #include<algorithm>
  4. #include<cstdio>
  5. #include<cstring>
  6. #include<cstdlib>
  7. #include<cmath>
  8. using namespace std;
  9. typedef long long s64;
  10.  
  11. const int ONE = ;
  12. const int MOD = 1e9 + ;
  13. const int all = ;
  14.  
  15. int x, n;
  16. double p;
  17. double f[][][][];
  18. double Ans;
  19. int val, num;
  20.  
  21. int get()
  22. {
  23. int res;char c;
  24. while( (c=getchar())< || c> );
  25. res=c-;
  26. while( (c=getchar())>= && c<= )
  27. res=res*+c-;
  28. return res;
  29. }
  30.  
  31. void Deal_first(int n)
  32. {
  33. int record[], num = , x = n;
  34. while(x)
  35. record[++num] = x & ,
  36. x >>= ;
  37. int j = , pos = , val = record[pos];
  38. for(pos = ; pos + j - <= num; j++)
  39. if(record[pos + j] != val) break;
  40.  
  41. f[][n & all][j][val] = ;
  42. }
  43.  
  44. int Get(int x)
  45. {
  46. int res = ;
  47. while(x % == ) res++, x >>= ;
  48. return res;
  49. }
  50.  
  51. int main()
  52. {
  53. x = get(), n = get(), p = (double)get() / ;
  54. Deal_first(x);
  55.  
  56. for(int i = ; i < n; i++)
  57. for(int s = ; s <= all; s++)
  58. for(int j = ; j <= ; j++)
  59. for(int k = ; k <= ; k++)
  60. {
  61. val = s >> - & ;
  62. if(val != k) num = ; else num = j + ;
  63. f[i + ][s << & all][num][val] += f[i][s][j][k] * p;
  64.  
  65. val = s == all ? (k ^ ) : k;
  66. if(val != k && k == ) num = ; else num = j;
  67. f[i + ][s + & all][num][val] += f[i][s][j][k] * ( - p);
  68. }
  69.  
  70. for(int s = ; s <= all; s++)
  71. for(int j = ; j <= ; j++)
  72. for(int k = ; k <= ; k++)
  73. {
  74. if(s == && k == ) val = j + ;
  75. else if(s == && k == ) val = ;
  76. else val = Get(s);
  77. Ans += f[n][s][j][k] * val;
  78. }
  79.  
  80. printf("%.8lf", Ans);
  81. }
  • 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. c#基类继承

    [ 塔 · 第 三 条 约 定 ] 编写一个多边形作为基类(成员:定点数)抽象方法(子类实现):体积.边长 正三角形类:成员 边长 长方形类:成员 长宽 using System; using Sys ...

  2. iOS开发跳转指定页面

    for (UIViewController *VC in self.navigationController.viewControllers) { if ([VC isKindOfClass:[Car ...

  3. AjaxPro怎么用

    AjaxPro是首家支持以各种方式通过javascript访问服务端.net的免费库,类似于SAJAX.它能把Javascript请求发送到.NET方法,服务端传回给Javascript,甚至包括串行 ...

  4. 微信小程序 功能函数 计时器

    let lovetime = setInterval(function () { let str = '(' + n + ')' + '重新获取' that.setData({ getText2: s ...

  5. 安装django 提示ImportError: No module named setuptools

    安装django前要先安装setuptools 先安装一些必要的包,否则会报错:Python build finished, but the necessary bits to build these ...

  6. 提升MyEclipse运行速度

    修改MyEclipse.ini文件中的,将-vmargs后面的参数修改为 -Xms256m -Xmx768m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:Max ...

  7. [计算机网络] DNS何时使用TCP协议,何时使用UDP协议

    DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议. 先简单介绍下TCP与UDP. ...

  8. InstallShield Limited Edition for Visual Studio 国内注册时国家无下拉框解决方法

    注册地址:http://learn.flexerasoftware.com/content/IS-EVAL-InstallShield-Limited-Edition-Visual-Studio 火狐 ...

  9. MVC绕过登陆界面验证时HttpContext.Current.User.Identity.Name取值为空问题解决方法

    Global.asax界面添加如下方法: void FormsAuthentication_Authenticate(object sender, FormsAuthenticationEventAr ...

  10. VisualVM使用方法

    VisualVM 简介 VisualVM 是一个工具,它提供了一个可视界面,用于查看 Java 虚拟机 (Java Virtual Machine, JVM) 上运行的基于 Java 技术的应用程序( ...