Accept: 189    Submit: 461
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

One integer number x is called "Mountain Number" if:

(1) x>0 and x is an integer;

(2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists).

For example, 111, 132, 893, 7 are "Mountain Number" while 123, 10, 76889 are not "Mountain Number".

Now you are given L and R, how many "Mountain Number" can be found between L and R (inclusive) ?

 Input

The first line of the input contains an integer T (T≤100), indicating the number of test cases.

Then T cases, for any case, only two integers L and R (1≤L≤R≤1,000,000,000).

 Output

For each test case, output the number of "Mountain Number" between L and R in a single line.

 Sample Input

3
1 10
1 100
1 1000

 Sample Output

9
54
384

 Source

“高教社杯”第三届福建省大学生程序设计竞赛

 
某次群赛的一个很水的数位dp,但脑抽了,不知道想到哪里去了
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int bits[];
ll dp[][][][];
ll dfs(int pos, int pre, int iso, int doing) {
if(pos == -) return ;
int End = doing ? bits[pos] : ;
ll& ans = dp[pos][pre][iso][doing];
if(ans != -) return ans;
ans = ;
for(int i = ; i <= End; ++i) {
if(iso && i <= pre) ans += dfs(pos - , i, , doing && i == End);
else if(!iso && i >= pre) ans += dfs(pos - , i, , doing && i == End);
}
return ans;
}
ll calc(ll x) {
int ls = ;
memset(dp, -, sizeof dp);
while(x) {
bits[ls++] = x % ;
x /= ;
}
return dfs(ls - , , , );
}
int main() {
ll n, m;
int _;
cin >> _;
while(_ --) {
cin >> n >> m;
cout << calc(m) - calc(n - ) << endl;
}
return ;
}

Fzu2109 Mountain Number 数位dp的更多相关文章

  1. FZU - 2109 Mountain Number 数位dp

    Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...

  2. 多校5 HDU5787 K-wolf Number 数位DP

    // 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...

  3. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  4. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  5. HDU 5787 K-wolf Number 数位DP

    K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacen ...

  6. HDU 3709 Balanced Number (数位DP)

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  7. beautiful number 数位DP codeforces 55D

    题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...

  8. BNU 13024 . Fi Binary Number 数位dp/fibonacci数列

    B. Fi Binary Number     A Fi-binary number is a number that contains only 0 and 1. It does not conta ...

  9. hdu 5898 odd-even number(数位dp)

    Problem Description For a number,if the length of continuous odd digits is even and the length of co ...

随机推荐

  1. 【python】入门学习(六)

    type() #检查变量或值得数据类型 >>> type(5) <class 'int'> 序列:包括字符串.元组和列表.序列都可以用索引.切片.len()(计算元素个数 ...

  2. UliPad双击没反应,UliPad打不开

    关于这个问题呢我也是蛋疼了好久,前几天是把这东西卸了重装,然后莫名其妙就可以了. 今天又遇到这问题,第一个想到的也是重装,发现不行,于是就搜了下,发现果然是网能的网友,下面贴图: 经过本屌几次尝试,鉴 ...

  3. VS2010编译Qt4.8.2的64版本库

    安装qt-win-opensource-4.8.2-vs2010.exe(从http://download.qt.io/archive/qt/4.8/4.8.2/下 载),这个是32位的,里面有编译好 ...

  4. maven编译时如何忽略单元测试

    共有两种解决办法 1.通过在命令行设置:-Dmaven.test.skip=true 如:mvn clean install tomcat:run -Dmaven.test.skip=true 2.通 ...

  5. [Android Pro] AAR and JAR

    svn status svn log --limit 3 > RELEASE_NOTE.txt cat RELEASE_NOTE.txt pwd project_name_prefix=&quo ...

  6. C++面向对象基础知识

    多态是为了接口重用,封装和继承是为了代码重用 子类重新定义父类虚函数的方法叫做继承,不是重载! 一.基本概念 对于C++中经常出现的函数名称相同但是参数列表或者返回值不同的函数,主要存在三种情况: 1 ...

  7. NYOJ题目100 1的个数

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsMAAAIqCAIAAABOpdBfAAAgAElEQVR4nO3drXLbzP834P9JhOdAgn ...

  8. Linux Shell 高级编程技巧2----shell工具

    2.shell工具    2.1.日志文件        简介            创建日志文件是很重要的,记录了重要的信息.一旦出现错误,这些信息对于我们排错是非常有用的:监控的信息也可以记录到日 ...

  9. 验证备份前设置CONFIGURE CONTROLFILE AUTOBACKUP ON/OFF; 的区别

    关于rman的,环境: oracle 10.2.0 rman nocatalog方式 1.首先设置 CONFIGURE CONTROLFILE AUTOBACKUP ON; 然后进行数据库全备份 RM ...

  10. 限制非安全IP访问

    这个是一个检测ip是否非法的php函数,适应于白名单,黑名单功能开发,主要场景应用于:api来源限制,访问限制等. /** * 安全IP检测,支持IP段检测 * @param string $ip 要 ...