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. 【leetcode】Swap Nodes in Pairs (middle)

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  2. 【leetcode】Word Search II(hard)★

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  3. 当对服务器端返回的极光推送数据请求时,AFN 的 GET 请求失败如何解决

    代码段 控制台   只需在 manager 那里添加一行代码即可 //传入json格式数据,不写则普通post     manager.requestSerializer = [AFJSONReque ...

  4. ios Push证书 转换步骤

    1.将aps_developer_identity.cer转换成aps_developer_identity.pem格式openssl x509 -in aps_developer_identity. ...

  5. hdu 5018 Revenge of Fibonacci

    大水题 #include<time.h> #include <cstdio> #include <iostream> #include<algorithm&g ...

  6. LR性能指标分析

    Memory: ·Available Mbytes 简述:可用物理内存数.如果Available Mbytes的值很小(4 MB或更小),则说明计算机上总的内存可能不足,或某程序没有释放内存. 参考值 ...

  7. python 取两数的百分比

    Python (r266:, Jan , ::) [GCC (Red Hat -)] on linux2 Type "help", "copyright", & ...

  8. jquery学习笔记----元素筛选

    1.eq()  筛选指定索引号的元素2.first() 筛选出第一个匹配的元素3.last() 筛选出最后一个匹配的元素4.hasClass() 检查匹配的元素是否含有指定的类5.filter() 筛 ...

  9. 【C#】Json数据 排版算法

    我从服务器上取得一串Json数据,然后想表示到画面上.不过服务器上取下的Json数据肯定是经过压缩的,空格和换行都没有.如果直接看,可读性非常差. 由于我这个软件是内部管理用的,使用者既能直接看懂Js ...

  10. C#委托(Action、Func、predicate)

    Predicate 泛型委托:表示定义一组条件并确定指定对象是否符合这些条件的方法.此委托由 Array 和 List 类的几种方法使用,用于在集合中搜索元素. public delegate boo ...