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. struts 拦截器 Interceptor

         拦截器是AOP中的概念,它本身是一段代码,可以通过定义“织入点”,来指定拦截器的代码在“织入点”的前后执行,从而起到拦截的作用.正如上面 Struts2的Reference中讲述的,Stru ...

  2. 网站配置好了,在本地能登录系统,但是挂在IIS上就无法登录了,提示数据库连接错误

    我用的VS2010开发的网站,但是挂在本机的IIS上的时候就无法登录了,提示错误如下:

  3. UI课堂笔记

    2016.7.18 + (UIColor *)blackColor; + (UIColor *)darkGrayColor;   深灰色 + (UIColor *)lightGrayColor;  浅 ...

  4. shared_ptr 和 unique_ptr

    c++11标准废除乐auto_ptr, C++ 标准库智能指针 使用这些智能指针作为将指针封装为纯旧 C++ 对象 (POCO) 的首选项. unique_ptr 只允许基础指针的一个所有者. 除非你 ...

  5. 无根树转有根树(dfs,tree)

    #include <bits/stdc++.h> #include <iostream> #include <queue> #include <stdio.h ...

  6. 二、JavaScript语言--JS基础--JavaScript进阶篇--选项卡切换效果

    利用JavaScript知识,实现选项卡切换的效果. 效果图: 文字素材: 房产: 275万购昌平邻铁三居 总价20万买一居     200万内购五环三居 140万安家东三环     北京首现零首付楼 ...

  7. python 连接sql server

    linux 下pymssql模块的安装 所需压缩包:pymssql-2.1.0.tar.bz2freetds-patched.tar.gz 安装: tar -xvf pymssql-2.1.0.tar ...

  8. oracle数据库出现“批处理中出现错误: ORA-00001: 违反唯一约束条件”解决方法

    最近使用oraclede impdp工具全库导入数据库时,在数据库里面使用出现如下情况. SQL state : 违反唯一约束条件 (GDXAORCL.SYS_C0055359) ; nested e ...

  9. MySQL5.6 on Windows 安装失败: String was not recognized as a valid DateTime

    在Win7,32位上安装MySQL5.6.21时出现日期/时间格式错误, 如下图所示: 错误描述为: String was not recognized as a valid DateTime. 下面 ...

  10. eclipse项目中关于导入的项目里提示HttpServletRequest 不能引用的解决办法

    eclipse项目中关于导入的项目里提示HttpServletRequest 不能引用的解决办法 当使用eclipse导入外部的web工程时,有时会提示HttpServletRequest, Serv ...