$CF55D [数位DP]$

数位DP+状压。
首先,按照数位DP的基本套路,每个个位数的最小公倍数为2520,所以只用考虑模2520的情况。考虑一个DP。dp[i][j][k]表示当前是第i位,2~9的数的集合为j,模2520为k的方案数。然后,就是数位DP的基本套路解决这道题。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read () {
LL res = ;
int f () ;
char ch = getchar ();
while (!isdigit(ch)) {
if (ch == '-') f = - ;
ch = getchar();
}
while (isdigit(ch)) res = (res << ) + (res << ) + (ch ^ ),ch = getchar();
return res * f ;
}
const int N=;
const int mod=;
int p[]= {,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,
};
int _lcm(int m,int n) {
return (m*n)/__gcd(m, n);
}
LL f[N][][mod+], bit[N], has[mod+];
inline LL dfs(int i,int lcm,int left, bool e) {
if(i==) return lcm&&left%p[lcm]== ;
if(!e && ~f[i][lcm][left]) return f[i][lcm][left];
LL ans=;
int u= e? bit[i]: ;
for(register int d=; d<=u; d++) {
int t= lcm? has[_lcm(p[lcm], max(d,))]: max(d,);
ans+=dfs(i-, t, (left*+d)%mod, e&&d==u);
}
return e==true? ans: f[i][lcm][left]=ans;
}
LL cal(LL n) {
int len=;
while(n) {
bit[++len]=n%;
n/=;
}
return dfs(len,,,true);
}
signed main() {
ios::sync_with_stdio(false);
memset(f,-,sizeof(f));
for(register int i=; i<; i++) has[p[i]]=i;
LL t=read();
while( t-- ) {
LL L=read(),R=read();
cout<<cal(R)-cal(L-)<<endl;
}
return ;
}

跑的好慢啊QwQ
随机推荐
- Windows 10 & Game Bar & YouTube & video records
Windows 10 & Game Bar & YouTube & video records Windows 10 C:\Users\xgqfrms\Videos\Captu ...
- [luoguP1896] [SCOI2005]互不侵犯King(状压DP)
传送门 先预处理出来一行中放置国王的所有情况和每种情况所用的国王个数. f[i][j][k]表示前i行放j个国王且最后一行的状态为k的方案数 状压DP即可 #include <cstdio> ...
- 【转】关于LIS和一类可以用树状数组优化的DP 预备知识
原文链接 http://www.cnblogs.com/liu-runda/p/6193690.html 预备知识 DP(Dynamic Programming):一种以无后效性的状态转移为基础的算法 ...
- onclick方法和$("").click()有不一样的地方
话说是这样的...昨天写了一个文件上传的功能,是这样的,用fastdfs上传成功后会有一个url... 然后我自己测试上传,包括在文件服务器里都能找到.. 然后就自己打包发版了,都很正常也没报错... ...
- POJ 1804 逆序对数量 / 归并排序
Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12175 Accepted: 6147 Descrip ...
- Codeforces Educational Round 23
A emmmmmmmmm B emmmmmmmmm C(套路) 题意: 给定n和s(n,s<=1e18),计算n以内有多少个数x满足(x-x的各个位置数字之和)>=s 分析: 容易想到如果 ...
- MongoDB C#驱动
烟波钓徒 MongoDB C#驱动 http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial 笔记 首先下载驱动.驱动有两个文件 Mongo ...
- mysql建表语句key的含义
CREATE TABLE `admin_role` ( `adminSet_id` varchar(32) NOT NULL, `roleSet_id` varchar(32) NOT NULL, ...
- node-V8
Node是基于V8引擎的,所以我们运行Js文件不会存在问题,下面演示一下: 因为安装Vscode后,会自动添加本路径到path,所以可以用 code yes.js 来执行创建文件 Vscode是基于N ...
- PAT Rational Arithmetic (20)
题目描写叙述 For two rational numbers, your task is to implement the basic arithmetics, that is, to calcul ...