题面:

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. Linux kernel parameter command line设置

    现在CPU2核以上比较普遍了,平时用linux上上网可能用不着双核甚至4核,大部分发行版内核都启用了CPU_HOTPLUG,到/sys/devices/system/cpu下可以看到文件夹cpu0.c ...

  2. VC++为你的程序增加内存泄露检测

    使用方法:  C++ Code  12345678910111213141516171819202122232425262728293031323334353637383940414243444546 ...

  3. 自动交互式脚本--expect

    我们经常会遇到一些需要与服务器程序打交道的场景,比如,从登陆某个服务器,然后进行某项工作.这很平常,但是如果把这个工作自动化进行,你就需要一个程序能自动做你要告诉机器的事情,这样,我们的expect就 ...

  4. Googlebot (Google Web search)

    w推测“域名解析过程中,Google crawlers中首先是Googlebo中的Google Web search上阵”. +-----+----------------+------------- ...

  5. Python在运维工作中的经典应用之ansible

    1.安装ansible wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo curl -o /e ...

  6. Python3.6编译安装以及python开发之virtualenv与virtualenvwrapper

    Python3.6编译安装 下载python源码包 先到安装目录 cd /opt 下载源码包 wget https://www.python.org/ftp/python/3.6.2/Python-3 ...

  7. Python之配置文件读写

    ConfigParser模块 一.创建配置文件 在D盘建立一个配置文件,名字为:test.ini 内容如下: [baseconf] host=127.0.0.1 port=3306 user=root ...

  8. 搭建高性能Jboss负载均衡集群

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/a1314517love/article/details/26836357 负载均衡集群是由两台或者两 ...

  9. 如何理解PHP的单例模式

    单例模式就是让类的一个对象成为系统中的唯一实例,避免大量的 new 操作消耗的资源. PHP的单例模式实现要求: 1.一个private的__construct是必须的,单例类不能在其它类中实例化,只 ...

  10. Apache Spark 2.0三种API的传说:RDD、DataFrame和Dataset

    Apache Spark吸引广大社区开发者的一个重要原因是:Apache Spark提供极其简单.易用的APIs,支持跨多种语言(比如:Scala.Java.Python和R)来操作大数据. 本文主要 ...