Description

The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets to be milked first. They can't even flip a coin because it's so hard to toss using hooves.

They have thus resorted to "round number" matching. The first cow picks an integer less than two billion. The second cow does the same. If the numbers are both "round numbers", the first cow wins,
otherwise the second cow wins.

A positive integer N is said to be a "round number" if the binary representation of N has as many or more zeroes than it has ones. For example, the integer 9, when written in binary form, is 1001. 1001 has two zeroes and two ones; thus, 9 is a round number. The integer 26 is 11010 in binary; since it has two zeroes and three ones, it is not a round number.

Obviously, it takes cows a while to convert numbers to binary, so the winner takes a while to determine. Bessie wants to cheat and thinks she can do that if she knows how many "round numbers" are in a given range.

Help her by writing a program that tells how many round numbers appear in the inclusive range given by the input (1 ≤ Start < Finish ≤ 2,000,000,000).

Input

Line 1: Two space-separated integers, respectively Start and Finish.

Output

Line 1: A single integer that is the count of round numbers in the inclusive range Start..Finish

Sample Input

2 12

Sample Output

6

题意:求s到e中二进制数 0的个数大于1的个数 的数的个数(语文不好见谅..)

思路:dp[i][j][k] i为数位 j为0的个数 k为1的个数 主要就是需要处理前导零 因为数位dp不可避免的要遍历前面全是零的情况 所以需要在递归的时候再加一个参数出现一以后再计算

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int bits[];
ll dp[][][];
ll dfs(int len,int numzero,bool ismax,int numone,bool haveone){
if(!len) return numzero>=numone;
if(!ismax&&dp[len][numzero][numone]>=) return dp[len][numzero][numone];
int up=ismax?bits[len]:;
ll ans=; int i;
for(i=;i<=up;i++){
if(i==&&haveone)
ans+=dfs(len-,numzero+,ismax&&i==up,numone,true);
else if(i==)
ans+=dfs(len-,numzero,ismax&&i==up,numone+,true);
else if(i==&&!haveone)
ans+=dfs(len-,numzero,ismax&&i==up,numone,false);
}
if(!ismax) dp[len][numzero][numone]=ans;
return ans;
}
ll solve(ll n){
int len=;
while(n){
bits[++len]=n%;
n/=;
}
return dfs(len,,true,,false);
}
int main(){
ios::sync_with_stdio(false);
ll s,e;
while(cin>>s>>e){
memset(dp,-,sizeof(dp));
cout<<solve(e)-solve(s-)<<endl;
}
return ;
}

poj 3252 Round Numbers(数位dp 处理前导零)的更多相关文章

  1. POJ 3252 Round Numbers(数位dp&amp;记忆化搜索)

    题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于 ...

  2. POJ - 3252 - Round Numbers(数位DP)

    链接: https://vjudge.net/problem/POJ-3252 题意: The cows, as you know, have no fingers or thumbs and thu ...

  3. poj 3252 Round Numbers 数位dp

    题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...

  4. $POJ$3252 $Round\ Numbers$ 数位$dp$

    正解:数位$dp$ 解题报告: 传送门$w$ 沉迷写博客,,,不想做题,,,$QAQ$口胡一时爽一直口胡一直爽$QAQ$ 先港下题目大意嗷$QwQ$大概就说,给定区间$[l,r]$,求区间内满足二进制 ...

  5. POJ3252 Round Numbers —— 数位DP

    题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Su ...

  6. Round Numbers(数位DP)

    Round Numbers http://poj.org/problem?id=3252 Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

  7. 4-圆数Round Numbers(数位dp)

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14947   Accepted: 6023 De ...

  8. poj3252 Round Numbers (数位dp)

    Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...

  9. POJ 3252 Round Numbers(组合)

    题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...

随机推荐

  1. Mysql占用CPU过高如何优化?(转)

    原文:http://bbs.landingbj.com/t-0-241441-1.html MySQL处在高负载环境下,磁盘IO读写过多,肯定会占用很多资源,必然CP会U占用过高. 占用CPU过高,可 ...

  2. C#设计模式之9:模板方法

    模板方法 模板方法是一个方法,定义了算法的步骤,并允许子类为一个或多个步骤提供实现. 本例中用冲泡咖啡和茶的例子来说明: 上图说明了冲泡咖啡和茶的步骤,可以看出冲泡咖啡和茶的步骤差不多,很相似,先来看 ...

  3. linux和sqlserver 2017的安装

    这两天一直在弄linux的安装过程.中间也遇到了不少的坑,主要是网络上的坑人的文章太多.都是坑,最后从redhat官网下载了iso文件,顺便看到官网推荐了一个fedora media writer的烤 ...

  4. 当mysql报错1045时的解决方法

    2.用记事本打开 添加 打开后,搜索mysqld关键字 找到后,在mysqld下面添加skip-grant-tables,保存退出. 如果保存在了c盘里不能修改那么就采用这样的方法 然后就可以修改c盘 ...

  5. PS中如何把图片颜色加到字体上去

    1.在PS中的图层中,将图片置于文字层的上方,同时按ctrl+alt+g键,这样就将文字范围以外的图像给剪切掉了.见附图下方的效果. 2.最终效果如下图: 参见:https://zhidao.baid ...

  6. HeapSter安装(k8s1.12以后废弃了)

    HeapSter InfluxDB(持久存储) Grafana 展示InfluxDB的数据(类似kibana) #安装InfluxDB #github https://github.com/kuber ...

  7. 用 Python分析朋友圈好友的签名

    需要用到的第三方库: numpy:本例结合wordcloud使用 jieba:对中文惊进行分词 PIL: 对图像进行处理(本例与wordcloud结合使用) snowlp:对文本信息进行情感判断 wo ...

  8. python好文章

    http://blog.csdn.net/csdnnews/article/details/78557392

  9. codeforces569B

    Inventory CodeForces - 569B Companies always have a lot of equipment, furniture and other things. Al ...

  10. 牛客网-2018年全国多校算法寒假训练营练习比赛(第四场)-A

    解题思路:二分图的最大匹配,但这题是所有点都遍历一遍,所以答案/2: 代码: #include<iostream> #include<algorithm> #include&l ...