题面:

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. log4j配置文件

    log4j.rootLogger=INFO,CONSOLElog4j.addivity.org.apache=truelog4j.appender.stdout=org.apache.log4j.Co ...

  2. Mac终端Screen命令使用指南

    (1)创建会话 使用命令“screen -S RunWork”来创建一个screen会话,命令执行之后,就会得到一个新的shell窗口,为了便于标示可以用快捷键Ctrl-a A(就是按下Ctrl+a键 ...

  3. JavaWeb的编码问题

    http://blog.csdn.net/yuhaiqiang_123/article/details/51811419

  4. AWS CLI 【S3】

    1.创建一个桶&删除一个桶 root@syavingc:~# aws s3 mb s3://syavingc #创建一个桶 make_bucket: syavingc root@syaving ...

  5. VS2010类模板更改,增加版权等等信息

    本文转载自XDOTNET 在开发过程中往往需要在每一个页面(类)增加注释等等内容,VS2010中可以修改模板,在原有模板中增加一个类,会引用System等等命名空间,以及一些程序集.下面我们来看看如何 ...

  6. 【黑金原创教程】【TimeQuest】【第七章】供源时钟与其他

    声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...

  7. 【BZOJ2287】【POJ Challenge】消失之物 背包动规

    [BZOJ2287][POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了 ...

  8. Python全栈day9(Python基础)

    Python基础 一,Windows安装Python3.5 下载地址:https://www.python.org/ftp/python/3.5.2/python-3.5.2rc1-amd64.exe ...

  9. PAT 1026 Table Tennis (30)

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  10. Spark 源码分析 -- Task

    Task是介于DAGScheduler和TaskScheduler中间的接口 在DAGScheduler, 需要把DAG中的每个stage的每个partitions封装成task 最终把taskset ...