链接

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

这次按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. POJ1077 Eight —— 经典的搜索问题

    题目链接:http://poj.org/problem?id=1077 Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  2. 织梦DEDE多选项筛选_联动筛选功能的实现_二次开发

    织梦默认的列表页没有筛选功能,但有时候我们做产品列表页的时候,产品的字段比较多,很多人都需要用到筛选功能,这样可以让用户更方便的找到自己所需要的东西,实现这个联动筛选功能需要对织梦进行二次开发,下面就 ...

  3. iOS多线程全套:线程生命周期,多线程的四种解决方案,线程安全问题,GCD的使用,NSOperation的使用

    目的 本文主要是分享iOS多线程的相关内容,为了更系统的讲解,将分为以下7个方面来展开描述. 多线程的基本概念 线程的状态与生命周期 多线程的四种解决方案:pthread,NSThread,GCD,N ...

  4. hdu 超级楼梯 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 哦--对了,这些题读者可以直接忽略,我只是想练习一下自己薄弱的地方...... 题目意思我就不说 ...

  5. random和string模块

    random模块import randomprint(random.random()) #随机打印一个浮点数print(random.randint(1,5)) #随机打印一个整数,包括5print( ...

  6. SPOJ:Divisors of factorial (hard) (唯一分解&分块优化)

    Factorial numbers are getting big very soon, you'll have to compute the number of divisors of such h ...

  7. 【字符串】BZOJ上面几个AC自动机求最为字串出现次数的题目

    (一下只供自己复习用,目的是对比这几个题,所以写得不详细.需要细节的可以参考其他博主) [BZOJ3172:单词] 题目: 某人读论文,一篇论文是由许多(N)单词组成.但他发现一个单词会在论文中出现很 ...

  8. [Selenium] WebDriver 操作 HTML5 中的 drag/drop

    以 jQuery UI 官方网站元素测试,地址:http://jqueryui.com/draggable/ 示例: package com.learningselenium.html5; impor ...

  9. nginx开发_调试日志

    接口列表 核心文件ngx_log.h 主要接口如下: ngx_log_error(level, log, err, fmt, ...) ngx_log_debug(level, log, err, f ...

  10. JNI 接口规范

    1. 简介 Java 本地接口概述 背景 JDK 1.0 本地方法接口 Java 运行时接口 原始本地接口和 Java/COM 接口 目标 Java 本地接口方法 利用 JNI 编程 JDK 1.1. ...