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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; long long dp[maxn];
int sum[] = {,,,,,,,,};
long long int N; inline long long res(int i){
return (<<i) + (<<(i-));
} int main()
{
freopen("E:\\acm\\input.txt","r",stdin);
dp[] = ;
for(int i=;i<=;i++){
dp[i] = *dp[i-] + (<<(i-));
}
int T;
cin>>T;
for(int cas=;cas<=T;cas++){
cin>>N;
printf("Case %d: ",cas);
if(N <= ){
printf("%d\n",sum[N]);
continue;
}
long long ans = ;
for(int i=;i>=;i--){
long long temp = <<i;
if(N >= temp){
ans += dp[i];
long long diff = N - res(i);
if(diff >= ){ //这个地方没有加等号WA了两次。
ans += diff + ;
}
N -= temp;
}
if(N == ) break;
}
cout<<ans+sum[N]<<endl;
}
}

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. 安装mysql数据库

    http://jingyan.baidu.com/article/f3ad7d0ffc061a09c3345bf0.html

  2. MYSQL使用指南(下)

    在上篇我们讲了登录.增加用户.密码更改等问题.下篇我们来看看MySQL中有关数据库方面的操作.注意:你必须首先登录到MYSQL中,以下操作都是在MYSQL的提示符下进行的,而且每个命令以分号结束. 一 ...

  3. IOS LocationManager定位国内偏移,火星坐标(GCJ-02)解决方法

    转载自:http://blog.csdn.net/swingpyzf/article/details/16972351 纠偏也可参考:http://www.2cto.com/kf/201310/253 ...

  4. Java8 map和reduce

    map final List<Integer> numbers = Arrays.asList(1, 2, 3, 4); final List<Integer> doubleN ...

  5. 解决SDK Manager无法更新问题

    因为google被封了,导致Android SDK Manager无法更新,解决方案如下: 1.选择tools->options,跳出Settings页面 2.设置HTTP Proxy代理,设置 ...

  6. android调试bug集锦 onActivityResult立即返回,并且被CANCEL

    症状: 在使用startActivityForResult调用照相机或者选择图片的时候,总是onActivityResult立马返回,resultCode=0 CANCEL. startActivit ...

  7. MDK —— configuration wizard

    学习RTX 的时候发现RTX的配置文件可以MDK的图形界面来配置,感觉这个非常好,直观.方便.健壮,可以避免程序员写入错误的数据.   参考: µVision User's Guide->Uti ...

  8. Xcode中使用GitHub详解

    为了熟悉git命令及将写的小Demo能够管理起来方便日后查询,所以选择使用GitHub. 现在我们来说说Xcode中如何使用GitHub--- 一.当然是要先有GitHub帐号并登录了(没有的注册一个 ...

  9. 我的iphone6退货之路

    开篇 匆匆这一年又快结束了,眼看年关将近,老婆的生日也快到了,正打算给老婆买个礼物,由于现在老婆用的手机是公司的工程机,而且还是低端产品,所以一直想给老婆改善改善,也算是对老婆这一年来辛苦的默默的支持 ...

  10. Map迭代器

            今天用到了,发现不会,随手谷歌之,整理如下. //Map是接口,刚才在那new Map,汗颜 Map<Character,Integer> mm = new HashMap ...