链接

也算是组合 以前按组合做过一次 忘记怎么做的了

这次按dp写的 dp[i][j][g][k] 表示第i位为k(0|1)而且有j个1,g个0的情况数

貌似写的麻烦了。。。这一类的题,进行逐位计算就可以 不过要很细心,边界处理 特殊情况处理什么的 。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[][][][];
int d[];
void init()
{
int i,j;
dp[][][][] = ;
dp[][][][] = ;
for(i = ; i <= ; i++)
for(j = ; j <= i ; j++)
{
int k = i-j;
dp[i][j][k][] += dp[i-][j][k-][]+dp[i-][j][k-][];
dp[i][j][k][] += dp[i-][j-][k][]+dp[i-][j-][k][];
} }
int judge(int x,int f)
{
int g=,i,j,e;
while(x)
{
d[++g] = x%;
x/=;
} int ans=;
for(j = ; j < g; j++)
for(i = ; i <= j ;i++)
{
int k = j-i; if(k>=i)
ans+=dp[j][i][k][];
}
int o = ;
for(i = g- ; i >= ; i--)
{
if(d[i+]) o--;
else o++;
if(!d[i]) continue;
if(i==)
{
o++;
if(o>=) ans++;
continue;
}
for(e = ; e <= i ; e++)
{
int k = i-e;
if(k-e+o>=)
ans+=dp[i][e][k][];
}
}
if(f)
{
o = ;
for(i = ; i<= g ;i++)
if(d[i]) o--;
else o++;
if(o>=) ans++;
}
return ans;
}
int main()
{
int a,b;
init();
while(cin>>a>>b)
{
cout<<judge(b,)-judge(a,)<<endl;
}
return ;
}

poj3252Round Numbers的更多相关文章

  1. poj3252Round Numbers【组合数】【数位dp】

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

  2. POJ3252-Round Numbers 数学

    题目链接:http://poj.org/problem?id=3252 题目大意: 输入两个十进制正整数a和b,求闭区间 [a ,b] 内有多少个Round number 所谓的Round Numbe ...

  3. POJ3252Round Numbers(数位dp)

    题意 给出区间$[A, B]$,求出区间内的数转成二进制后$0$比$1$多的数的个数 $1 \leqslant A, B \leqslant 2,000,000,000$ Sol 比较zz的数位dp ...

  4. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  5. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  6. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  7. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  8. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  9. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

随机推荐

  1. python 2: 解决python中的plot函数的图例legend不能显示中文问题

     问题: 图像标题.横纵坐标轴的标签都能显示中文名字,但是图例就是不能显示中文,怎么解决呢?  解决: plt.figure() plt.title(u'训练性能', fontproperties=f ...

  2. IOS中UIAlertView(警告框)常用方法总结

    一.初始化方法 - (instancetype)initWithTitle:(NSString *)title message:(NSString*)message delegate:(id /*&l ...

  3. yum下载对应内核版本的kernel-devel

    1 查看内核版本 uname -r 2 查看目前已有的kernel-devel uname -a ; rpm -qa kernel\* | sort 3 下载对应版本 $ sudo yum insta ...

  4. html的书写规范,有哪些注意点

    1.最开始的声明格式与编码格式,注意html5与和html4.0的区别,注意对不同浏览器的渲染作用: 2.<head></head>标签中的相关内容的编写: 3.确保引入的jq ...

  5. i2c_set_clientdata函数【转】

    本文转载自‘:http://blog.csdn.net/jk198310/article/details/43738367 在i2c驱动中有很多函数和数据结构,很多一时难以理解,所以写下本文共同学习. ...

  6. POJ3414 Pots —— BFS + 模拟

    题目链接:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. Java 远程调用之Hessian简例

    1. [代码]1.服务接口(Hello.java) package server; public interface Hello { String hello(String name);}2. [代码 ...

  8. hdu 2066 一个人的旅行 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目意思:给出T条路,和草儿家相邻的城市编号,以及草儿想去的地方的编号.问从草儿家到达草儿想去的 ...

  9. IOCP编程小结(中)

    上一篇主要谈了一些基本理念,本篇将谈谈我个人总结的一些IOCP编程技巧. 网络游戏前端服务器的需求和设计 首先介绍一下这个服务器的技术背景.在分布式网络游戏服务器中,前端连接服务器是一种很常见的设计. ...

  10. Linux终端那件事儿

    我们将会讨论如何更好的控制用户终端:也就说是键盘输入与屏幕输出.除了这些,我们还会了解我们编写的程序如何由用户处读取输入,即使是在输入重定向的情况下,以及确保输出到屏幕的正确位置.这里所提供的一些底层 ...