题目问区间有多少个数字的二进制0的个数大于等于1的个数。

用数学方法求出0到n区间的合法个数,然后用类似数位DP的统计思想。

我大概是这么求的,确定前缀的0和1,然后后面就是若干个0和若干个1的不重复全排列数。。

写得挺痛苦的。。另外A[i][j]表示i个0和j个1的不重复全排列数,即A[i][j]=(i+j)!/i!/j!,这个可以从A[i-1][j]或A[i][j-1]求出来,这样就不用担心乘法溢出了。

 #include<cstdio>
#include<cstring>
using namespace std;
long long d[][];
long long cnt(int zero,int one,int len){
long long res=;
for(int i=; i<=len; ++i){
int j=len-i;
if(i+zero<j+one) continue;
res+=d[i][j];
}
return res;
}
long long calu(int a){
int len=;
while(len!=- && ((a>>len)&)==) --len;
if(len==-) return ;
long long res=;
for(int i=; i<len; ++i){
res+=cnt(,,i);
}
int zero=,one=;
for(int i=len-; i>=; --i){
if((a>>i)&){
res+=cnt(zero+,one,i);
++one;
}else{
++zero;
}
}
zero=; one=;
for(int i=; i<=len; ++i){
if((a>>i)&) ++one;
else ++zero;
}
return res+(zero>=one);
}
int main(){
d[][]=;
for(int i=; i<; ++i){
for(int j=; j<; ++j){
d[i+][j]=d[i][j]*(i+j+)/(i+);
d[i][j+]=d[i][j]*(i+j+)/(j+);
}
}
int a,b;
while(~scanf("%d%d",&a,&b)){
printf("%lld\n",calu(b)-calu(a-));
}
return ;
}

POJ3252 Round Numbers(不重复全排列)的更多相关文章

  1. [BZOJ1662][POJ3252]Round Numbers

    [POJ3252]Round Numbers 试题描述 The cows, as you know, have no fingers or thumbs and thus are unable to ...

  2. poj3252 Round Numbers

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7625   Accepted: 2625 Des ...

  3. POJ3252 Round Numbers —— 数位DP

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

  4. poj3252 Round Numbers(数位dp)

    题目传送门 Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16439   Accepted: 6 ...

  5. poj3252 Round Numbers (数位dp)

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

  6. POJ3252 Round Numbers 【数位dp】

    题目链接 POJ3252 题解 为什么每次写出数位dp都如此兴奋? 因为数位dp太苟了 因为我太弱了 设\(f[i][0|1][cnt1][cnt0]\)表示到二进制第\(i\)位,之前是否达到上界, ...

  7. poj3252 Round Numbers[数位DP]

    地址 拆成2进制位做dp记搜就行了,带一下前导0,将0和1的个数带到状态里面,每种0和1的个数讨论一下,累加即可. WA记录:line29. #include<iostream> #inc ...

  8. POJ3252 Round Numbers 题解 数位DP

    题目大意: 求区间 \([x,y]\) 范围内有多少数的二进制表示中的'0'的个数 \(\ge\) '1'的个数. 解题思路: 使用 数位DP 解决这个问题. 我们设状态 f[pos][num0][n ...

  9. 题解【POJ3252】Round Numbers

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

随机推荐

  1. MySQL数据库InnoDB引擎下服务器断电数据恢复

    说明: 线上的一台MySQL数据库服务器突然断电,造成系统故障无法启动,重新安装系统后,找到之前的MySQL数据库文件夹. 问题: 通过复制文件的方式对之前的MySQL数据库进行恢复,发现在程序调用时 ...

  2. 对原型prototype的详解

    刚开始接触对象原型时大脑就开始起义了,脑子就转不灵清了.就感觉怎么着这个概念就是灌输不进去,俗称断路.后面找了很多资料,最主要的还是要借助于<JavaScript语言精髓>这本书,让我对这 ...

  3. hdu4255筛素数+广搜

    Mr. B has recently discovered the grid named "spiral grid".Construct the grid like the fol ...

  4. typedef 各类定义,各类问题大全

    第一篇:typedef struct与struct的区别 1. 基本解释 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数据类型(int,char等)和自定 ...

  5. php中global与$GLOBALS的用法及区别-转载

    php中global 与 $GLOBALS[""] 差别 原本觉得global和$GLOBALS除了写法不一样觉得,其他都一样,可是在实际利用中发现2者的差别还是很大的! 先看下面 ...

  6. linux下查看文件夹的大小

    du -sh du -sh dir_name/ du -sm * | sort -n //统计当前目录大小 并安大小排序 转自:http://www.jb51.net/LINUXjishu/77450 ...

  7. codeforces B. Xenia and Spies 解题报告

    题目链接:http://codeforces.com/problemset/problem/342/B 题目意思:有n个spy,编号从1-n,从左到右排列.现在的任务是,spy s要把信息传递到spy ...

  8. tomcat启动,输出system.out.println()

    tomcat6.0在使用System.out.println("aa")的时候,用cmd启动startup.bat,弹出的那个cmd窗口看到 还可以看logs/catalina.o ...

  9. 【python-mysql】在ubuntu下安装python-mysql环境

    1.先安装mysql sudo apt-get install mysql-server apt-get isntall mysql-client sudo apt-get install libmy ...

  10. DLL工程没有生成对应的lib文件

    要至少导出一个函数/变量才能产生lib 也就是说得用到__declspec(dllexport)