题面:

Problem I. Increasing or Decreasing
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 512 mebibytes
We all like monotonic things, and solved many problems about that like Longest Increasing Subsequence
(LIS). Here is another one which is easier than LIS (in my opinion).
We say an integer is a momo number if its decimal representation is monotonic. For example, 123, 321,
777 and 5566 are momo numbers; But 514, 50216 and 120908 are not.
Please answer m queries. The i-th query is a interval [li; ri], and please calculate the number of momo
numbers in it.
Input
The first line contains an integer m.
Each of the following m lines contains two integers li; ri.
• 1 ≤ m ≤ 105
• 1 ≤ li ≤ ri ≤ 1018
Output
For each query, please output the number of momo numbers in that range.
Example

standard input standard output
2
1 100
100 200
100
48

思路:

  数位dp

 #include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; LL dp[][][];
int num[];
LL dfs(int pos,int s,int pre,int led,int lmt)
{
if(pos<) return !led;
if(!lmt&&~dp[pos][pre][s]) return dp[pos][pre][s];
int mx=lmt?num[pos]:;
LL ans=;
for(int i=;i<=mx;i++)
if(led)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else
{
if(s==&&i>pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i<pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i==pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i>=pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
else if(s==&&i<=pre)
ans+=dfs(pos-,,i,!i&&led,lmt&&i==mx);
}
//printf("lm:%d dp[%d][%d][%d]:%I64d\n",lmt,pos,pre,s,ans);
if(!lmt) dp[pos][pre][s]=ans;
return ans;
}
LL go(LL x)
{
if(x<) return ;
int cnt=;
LL ans=;
while(x)
num[++cnt]=x%,x/=;
for(int i=;i<num[cnt];i++)
ans+=dfs(cnt-,,i,!i,);
return ans+dfs(cnt-,,num[cnt],,);
} int main(void)
{
LL m,l,r;
cin>>m;
memset(dp,-,sizeof dp);
while(m--)
{
scanf("%lld%lld",&l,&r);
//printf("%I64d\n",go(r));
printf("%lld\n",go(r)-go(l-));
}
return ;
}

Problem I. Increasing or Decreasing MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016的更多相关文章

  1. 【循环节】【矩阵乘法】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem F. Fibonacci of Fibonacci

    题意:F(n)为斐波那契数列的第n项,问你F(F(n)) mod 20160519的值. 发现有循环节,F(26880696)=0,F(26880697)=1,.... 于是两次矩乘快速幂即可. #i ...

  2. 【推导】【凸包】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem D. Drawing Hell

    平面上n个点,两个人交替决策,用线段连接两个点,但不能跨越其他点或者已经存在的线段.不能做的人算输,问你谁赢. 实际上,跟两个人的决策无关,n个点将平面三角剖分,只需要算出有几条边即可. 凸包上如果有 ...

  3. 【Trie】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem B. Be Friends

    题意:一个n个点的完全图,点带权,边权是两端点点权的异或值.问你最小生成树. 一个性质,把所有点按照二进制最高位是否为1划分为2个集合,那么这两个集合间只会有一条边.可以递归处理. 把所有点建成01T ...

  4. 【分块】MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016 Problem A. As Easy As Possible

    给你一个字符串,多次区间询问,问你在该区间内最多能有几个easy重复的子序列. 显然如果只有一次询问,从左到右贪心做即可. 分块,预处理任意两块间的答案,不过要把以e a s y开头的四个答案都处理出 ...

  5. 2016 MIPT Pre-Finals Workshop Taiwan NTU Contest

    2016弱校联盟十一专场10.5 传送门 A. As Easy As Possible 假设固定左端点,那么每次都是贪心的匹配\(easy\)这个单词. 从\(l\)开始匹配的单词,将\(y\)的位置 ...

  6. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  7. 即将进行论文答辩的我发现MyEclipse 2016 激活过期害得我又一次把 MyEclipse 2016 给重新激活注册,详细的图文解说激活过程

    背景: 在家美滋滋的上着网课享受着因为疫情带来的平静,没想到随着微信.钉钉铃声响起打破了我半年以来的平静的生活:通知我们过完劳动节要进行答辩,由于我的答辩项目是由 MyEclipse 这个工具编写的我 ...

  8. 【博弈论】【SG函数】【线段树】Petrozavodsk Summer Training Camp 2016 Day 9: AtCoder Japanese Problems Selection, Thursday, September 1, 2016 Problem H. Cups and Beans

    一开始有n个杯子,每个杯子里有一些豆子,两个人轮流操作,每次只能将一个豆子移动到其所在杯子之前的某个杯子里,不过可以移动到的范围只有一段区间.问你是否先手必胜. 一个杯子里的豆子全都等价的,因为sg函 ...

  9. 【线段树】Petrozavodsk Summer Training Camp 2016 Day 6: Warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, 2016 Problem H. Hay

    有一些草,一开始高度都是0,它们的生长速率不同. 给你一些单增的日期,在这些日期要将>b的草的部分都割掉,问你每次割掉的部分有多少. 将草的生长速率从大到小排序,这样每次割掉的是一个后缀,而且不 ...

随机推荐

  1. SQL命令优化(积累)

    与数据库交互的基本语言是sql,数据库每次解析和执行sql语句多需要执行很多步骤.以sql server为例,当数据库收到一条查询语句时,语法分析器会扫描sql语句并将其分成逻辑单元(如关键词.表达式 ...

  2. linux配置防火墙打开3306端口

      安装完MYSQL服务器后在本机所有操作都正常, 但在其它机器上远程访问这个MYSQL服务器时怎么都连接不上.  shit! 怀疑是端口问题, 结果: telnet 192.168.1.245 33 ...

  3. Nuget包制作最佳解决方案

    https://www.cnblogs.com/drea/p/8418717.html 最近研究ABP框架,下载其全套源码,想“据为己有”,这样添加功能或者修改源码的话就非常方便了,否则搭建项目直接用 ...

  4. 编程之美 set 11 买书问题

    题目 书店搞促销, 同时购买多卷书时, 有机会享受优惠 2本优惠 5%, 3本 10%, 4 本 20% 5 本 25% 设计算法, 求解购买一本书的最低价格 分析 1. 第一个感觉是一次购买的越多省 ...

  5. ArcGIS 相同要素类的多Shp文件或多要素合并

  6. C语言基础之水仙花数

    题目:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身. 例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方. 程序分析:利用for循 ...

  7. vue+webpack2实现路由的懒加载

    当打包构建应用时,Javascript 包会变得非常大,影响页面加载.如果我们能把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了. 结合 Vue 的异步组 ...

  8. 如何使用phpmyadmin建立外键约束

    之前都是用sql语句进行的主外键的关联,现在用可视化的phpmyadmin感觉方便了很多,但是在做主外键约束的时候却十中找不到操作在哪里.网上搜索的也是千奇百怪五花八门的,都说的很晦涩,很多都说需要使 ...

  9. IOS 7 自定义的UIAlertView不能在iOS7上正常显示

    本文转载至 http://blog.csdn.net/hanbing861210/article/details/13614405 众所周知,当伟大的iOS7系统发布后,表扬的一堆.谩骂的也一片,而对 ...

  10. List<Integer>.remove()的一个小细节

    不废话,先上代码: ArrayList<Integer> col = new ArrayList<Integer>(); System.out.println("In ...