链接

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

这次按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. top swap

    显示交换空间(虚拟内存)的使用情况

  2. 10162 - Last Digit (数论+周期规律)

    UVA 10162 - Last Digit 题目链接 题意:求S=(11+22+...NN)%10 思路:打出0-9的每一个周期,发现周期为1或2或4.所以S是以20一个周期,打出表后发现20为4. ...

  3. Codility经典算法题之九:MissingInteger

    Task description: This is a demo task. Write a function: that, given an array A of N integers, retur ...

  4. Spark基本原理

    仅作<Spark快速大数据分析>学习笔记 定义:Spark是一个用来实现 快速 而 通用 的集群计算平台:(通用的大数据处理引擎:) 改进了原Hadoop MapReduce处理模型,体现 ...

  5. POJ 1861 Network (Kruskal算法+输出的最小生成树里最长的边==最后加入生成树的边权 *【模板】)

    Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14021   Accepted: 5484   Specia ...

  6. HDU 5178 pairs —— 思维 + 二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others)     ...

  7. java多线程实现简单队列

    1.创建Queue.java public class Queue { private LinkedList<Object> list = new LinkedList<Object ...

  8. 在canvas标签和style中定义width和height

    在canvas标签中定义width.height跟在style中定义width.height是不同的.canvas标签的width和height是画布实际宽度和高度,就是在这个上面绘制图形.style ...

  9. python中PIL.Image和OpenCV图像格式相互转换

    PIL.Image转换成OpenCV格式: import cv2 from PIL import Image import numpy image = Image.open("plane.j ...

  10. iOS成员变量、实例变量、属性变量三者的联系与区别

    一.类Class中的属性property 在ios第一版中: 我们为输出口同时声明了属性和底层实例变量,那时,属性是oc语言的一个新的机制,并且要求你必须声明与之对应的实例变量,例如: 注意:(这个是 ...