题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4521

dfs真好用~

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=;
int dg[N];
ll l,r,dp[N][][N][][][];
ll dfs(int p,int len,int lst,bool p0,bool p1,bool ok,bool fx)
{
if(!p){return ok&(!(p0&p1));}
if(!fx&&dp[p][len][lst][p0][p1][ok]!=-)return dp[p][len][lst][p0][p1][ok];
int st=;if(p==)st=;
int end=;if(fx)end=dg[p];
ll ret=;
for(int i=st;i<=end;i++)
{
int lenn=;if(i==lst)lenn=len+;
if(lenn>)lenn=;
ret+=dfs(p-,lenn,i,p0|(i==),p1|(i==),ok|(lenn==),fx&(i==dg[p]));
}
if(!fx)dp[p][len][lst][p0][p1][ok]=ret;
return ret;
}
ll calc(ll x)
{
if(x<1e10)return ;
for(int i=;i<=;i++)dg[i]=x%,x/=;
memset(dp,-,sizeof dp);
return dfs(,,,,,,);
}
int main()
{
scanf("%lld%lld",&l,&r);
printf("%lld\n",calc(r)-calc(l-));
return ;
}

最新文章

  1. Java基础-重写System.out.println方法
  2. InnoDB 存储引擎的锁机制
  3. Java深入 - Java 内存分配和回收机制
  4. 身份证号码自动生成程序(Python)
  5. Android中的CharSequence和String
  6. CSS控制文本超出指定宽度后用省略号代替,CSS控制文本不换行
  7. thinkphp 3+ 观后详解 (2)
  8. 3C Tic-tac-toe
  9. Identity 验证,Authorize 特性
  10. setTimeout的若干坑
  11. poj2486 Apple Tree (树形dp)
  12. POJ 2411
  13. Spark技术内幕: 如何解决Shuffle Write一定要落盘的问题?
  14. 导入项目 idea
  15. 单元测试-unittest模块
  16. Ubuntu中通过SuperVisor添加守护进程
  17. mysql字符函数
  18. python日期加减法操作
  19. MVC 多submit
  20. ORB feature(O for orientation)

热门文章

  1. OpenCASCADE圆与平面求交
  2. 《DSP using MATLAB》Problem 8.25
  3. java基础之BigInteger
  4. [COCI2019] Mobitel
  5. Apache Pig学习笔记(二)
  6. Redis List类型学习
  7. 第一个WindowService服务
  8. [转]在C#代码中应用Log4Net系列教程(附源代码)
  9. linux学习(三)-----linux用户管理、实用指令
  10. java监控文件夹下的文件变化使用jnotify