题目链接:http://lightoj.com/volume_showproblem.php?problem=1032

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <queue>
  7. #include <vector>
  8. using namespace std;
  9.  
  10. const int maxn = ;
  11. const int INF = 0x3f3f3f;
  12.  
  13. long long dp[maxn];
  14. int sum[] = {,,,,,,,,};
  15. long long int N;
  16.  
  17. inline long long res(int i){
  18. return (<<i) + (<<(i-));
  19. }
  20.  
  21. int main()
  22. {
  23. freopen("E:\\acm\\input.txt","r",stdin);
  24. dp[] = ;
  25. for(int i=;i<=;i++){
  26. dp[i] = *dp[i-] + (<<(i-));
  27. }
  28. int T;
  29. cin>>T;
  30. for(int cas=;cas<=T;cas++){
  31. cin>>N;
  32. printf("Case %d: ",cas);
  33. if(N <= ){
  34. printf("%d\n",sum[N]);
  35. continue;
  36. }
  37. long long ans = ;
  38. for(int i=;i>=;i--){
  39. long long temp = <<i;
  40. if(N >= temp){
  41. ans += dp[i];
  42. long long diff = N - res(i);
  43. if(diff >= ){ //这个地方没有加等号WA了两次。
  44. ans += diff + ;
  45. }
  46. N -= temp;
  47. }
  48. if(N == ) break;
  49. }
  50. cout<<ans+sum[N]<<endl;
  51. }
  52. }

lightoj 1032 二进制的dp的更多相关文章

  1. Fast Bit Calculations LightOJ - 1032

    Fast Bit Calculations LightOJ - 1032 题意:求0到n的所有数的二进制表示中,"11"的总数量.(如果有连续的n(n>2)个1,记(n-1) ...

  2. bzoj3209 花神的数论题 (二进制数位dp)

    二进制数位dp,就是把原本的数字转化成二进制而以,原来是10进制,现在是二进制来做,没有想像的那么难 不知到自己怎么相出来的...感觉,如果没有一个明确的思路,就算做出来了,也并不能锻炼自己的能力,因 ...

  3. LightOJ 1032 - Fast Bit Calculations 数位DP

    http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...

  4. lightoj 1032 - Fast Bit Calculations(数位dp)

    A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...

  5. LightOJ - 1032 数位DP

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...

  6. 51nod 1413 权势二进制 背包dp

    1413 权势二进制 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB  一个十进制整数被叫做权势二进制,当他的十进制表示的时候只由0或1组成.例如0,1,101, ...

  7. lightOJ 1017 Brush (III) DP

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...

  8. lightoj 1381 - Scientific Experiment dp

    1381 - Scientific Experiment Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lightoj.com/vo ...

  9. BZOJ3329: Xorequ(二进制数位dp 矩阵快速幂)

    题意 题目链接 Sol 挺套路的一道题 首先把式子移一下项 \(x \oplus 2x = 3x\) 有一件显然的事情:\(a \oplus b \leqslant c\) 又因为\(a \oplus ...

随机推荐

  1. Centos6.5 install Python2.7 & django & mysql & apache

    #! /bin/bash#su root#get python2.7wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz #ins ...

  2. JS 定時刷新父類頁面

    function timeCount() { var url = "MAC.aspx"; parent.location.href = url; } function beginC ...

  3. Struts2多文件上传

    第一步:首先创建一个多文件上传的页面 <html> <head> <meta http-equiv="Content-Type" content=&q ...

  4. asp.net mvc5 设置Area下的为启动页

    只需修改App_Start文件夹下RouteConfig中RegisterRoutes方法 public static void RegisterRoutes(RouteCollection rout ...

  5. C#程序中:如何修改xml文件中的节点(数据)

    要想在web等程序中实现动态的数据内容给新(如网页中的Flash),不会更新xml文件中的节点(数据)是远远不够的,今天在这里说一个简单的xml文件的更新,方法比较基础,很适合初学者看的,保证一看就懂 ...

  6. linux自定义开机启动服务

    转 http://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html 手工创建服务 1.在/etc/rc.d/init.d目录下创建shel ...

  7. Python核心编程2第三章课后练习

    1. 标识符.为什么Python 中不需要变量名和变量类型声明? Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程.每个变量在内存中创建,都包括变量的标识,名称和数据这些信息.每 ...

  8. iOS: 学习笔记, 添加一个带界面约束的控制器

    1. 创建一个空iOS应用程序(Empty Application). 2. 添加加控制器类. 修改控制器类的viewDidLoad - (void)viewDidLoad { [super view ...

  9. Noah的学习笔记之Python篇:装饰器

    Noah的学习笔记之Python篇: 1.装饰器 2.函数“可变长参数” 3.命令行解析 注:本文全原创,作者:Noah Zhang  (http://www.cnblogs.com/noahzn/) ...

  10. HTML+JS版本的俄罗斯方块

    <!doctype html><html><head></head><body> <div id="box" st ...