题意:在区间中,他们化成2进制的数的0的个数大于等于1的数有多少个。

  思路:我们需要记录上一次0和1的个数,此外我们还要特别注意一下前导0。

  如果前面全是0的时候我们就要注意下一位是不是还是0,如果一直都是0那么这个数也满足条件。

/*  gyt
Live up to every day */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = +;
const ll maxm = 1e7;
const int mod = ;
const int INF = <<;
const db eps = 1e-;
const ll Max=1e19;
int a[maxn];
ll dp[maxn][maxn][maxn]; ll dfs(int pos, int num0, int num1, int limit, int ncan) {
if (pos==-) {
if (ncan) return ;
if (num0>=num1) return ;
return ;
}
if (!limit && !ncan && dp[pos][num0][num1]!=-) return dp[pos][num0][num1];
int up=limit?a[pos]:;
ll tmp=;
for (int i=; i<=up; i++) {
if (ncan) {
if (i==)
tmp+=dfs(pos-, , , limit&&i==a[pos], );
else
tmp+=dfs(pos-, , , limit&&i==a[pos], );
}
else {
if (i==)
tmp+=dfs(pos-, num0+, num1, limit&&i==a[pos], );
else
tmp+=dfs(pos-, num0, num1+, limit&&i==a[pos], );
}
}
if (!limit) dp[pos][num0][num1]=tmp;
return tmp;
}
ll deal(ll x) {
int pos=;
while(x) {
a[pos++]=x%;
x/=;
}
dfs(pos-, , , , );
}
void solve() {
ll n, m; scanf("%lld%lld", &n, &m);
memset(dp, -, sizeof(dp));
ll a=deal(m), b=deal(n-);
//cout<<a<<" "<<b<<endl;
printf("%lld\n", a-b);
}
int main() {
int t=;
//freopen("in.txt", "r", stdin);
//scanf("%d", &t);
for (int T=; T<=t; T++) {
solve();
}
}

POJ-3252 Avenger的更多相关文章

  1. POJ 3252 (数位DP)

    ###POJ 3252 题目链接 ### 题目大意:给你一段区间 [Start,Finish] ,在这段区间中有多少个数的二进制表示下,0 的个数 大于等于 1 的个数. 分析: 1.很显然是数位DP ...

  2. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  3. POJ 3252 Round Numbers(组合)

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

  4. poj 3252

    http://poj.org/problem?id=3252//自己搞了很长时间...现在刚刚有点明白.. 1 #include <iostream> using namespace st ...

  5. [poj 3252]数位dp前导0的处理

    通过这个题对于数位dp中前导0的处理有了新的认识. 题目链接:http://poj.org/problem?id=3252 //http://poj.org/problem?id=3252 #incl ...

  6. poj 3252 Round Numbers 【推导·排列组合】

    以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-R ...

  7. POJ 3252 Round Numbers

     组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...

  8. Greedy:Fence Repair(POJ 3252)

    Fence Repair 问题大意:农夫约翰为了修理栅栏,要将一块很长的木块切割成N块,准备切成的木板的长度为L1,L2...LN,未切割前的木板的长度恰好为切割后木板的长度的总和,每次切断木板的时候 ...

  9. poj 3252 组合数

        主要考察组合数知识,初始化的时候参考公式 首先先推个公式,就是长度为len的Round Numbers的个数.      长度为len,第一位肯定是1了.      那么后面剩下 len-1位 ...

  10. POJ 3252 Round Numbers(数位dp)

    题意:给定区间[l,r],l < r ,求区间中满足条件的正整数的个数:二进制表示下0的个数不少于1的个数. 分析:f(x)表示<=x时满足条件的数的个数,所求问题即为f(r)-f(l-1 ...

随机推荐

  1. IDEA错误:Cannot start compilation: the output path is not specified for module "Test". Specify the out

    错误是发生在从github上checkout自己的项目时.因为没有将配置文件一起上传,所以在运行Java程序时有了这个报错: Cannot start compilation: the output ...

  2. 使用scaleBitmap类缩放和拉伸

    使用scaleBitmap类缩放和拉伸 位图,画架,图形,小贴士我们一直在寻找在createJS中优化.简化或创建更好工作流的方法,scaleBitmap就是一个很好的例子.使用旧的flash方法,在 ...

  3. 全国高校绿色计算大赛 预赛第一阶段(C++)第4关:计算日期

    挑战任务 我们吃的食物都有保质期,现在食品监督管理局想要制作一个能准确计算食品过期日期的小程序,需要请你来进行设计. 例如:A食品在2018年1月1日生产,保质期是20天,则它的过期日期在2018年1 ...

  4. CentOS Find命令

    find命令用来在指定目录下查找文件.任何位于参数之前的字符串都将被视为欲查找的目录名.如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件.并且将查找到的子目录和文件全部进 ...

  5. pandas数据处理攻略

    首先熟悉numpy随机n维数组的生成方法(只列出常用的函数): np.random.random([3, 4]) #生成shape为[3, 4]的随机数组,随机数范围[0.0, 1.0) np.ran ...

  6. python3之subprocess常见方法使用

    一.常见subprocess方法 1.subprocess.getstatusoutput(cmd) 官方解释: Return (exitcode, output) of executing cmd ...

  7. swift - 封装百度地图

    1. #import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件 #import <BaiduMapAPI_Map/B ...

  8. java 动手动脑解决问题

    1.Java的基本运行单位是类还是方法?是类,因为没有方法可以独立存在,方法在逻辑上属于类或属于对象. 2.类的组成成员?成员变量,成员方法. 3.成员变量的种类? byte short int lo ...

  9. 让listView gridView全部扩展开

    public class NoScrollListView extends ListView {    public NoScrollListView(Context context, Attribu ...

  10. linux 常见基础知识(此文章将会在整个linux学习过程中,不断添加)

    1,linux 文件类型 普通文件 目录文件 链接文件 块设备 字符设备 Socket 管道文件 - d l b c s p 2,linux 文件属性 蓝色 绿色 浅蓝色 红色 灰色 目录 可执行文件 ...