$dp[x][p][pp]$表示第x位,当前已有数字mod 2520(1~9数字的lcm)为p,当前各位数字的lcm为pp

观察到数组太大,考虑压缩,第三维lcm最多只有9个数字,打表发现最多只有48个状态,压掉第三维即可

打表用一个状压然后set维护(广搜也可以)即可

有一个坑点:题目里似乎没有说关于0的事情(即数字里出现0)但是有人在CF上打这个比赛的时候问了出题人,碰到0不要管即可!!!

打表代码:

 set<int>s;
inline void Make(int x){
int ans=;
for(int i=;i<;i++){
if(((<<i)&x)) ans=lcm(ans,i+);
}s.insert(ans);
}
inline void States_Maker(){
int ans=;
for(int i=;i<(<<);i++)Make(i);
while(!s.empty()){
cout<<*s.begin()<<",";
s.erase(s.begin());
}
}

解题代码:

 #include<bits/stdc++.h>
#define int long long
#define writeln(x) write(x),puts("")
#define writep(x) write(x),putchar(' ')
using namespace std;
inline int read(){
int ans=,f=;char chr=getchar();
while(!isdigit(chr)){if(chr=='-') f=-;chr=getchar();}
while(isdigit(chr)){ans=(ans<<)+(ans<<)+chr-;chr=getchar();}
return ans*f;
}void write(int x){
if(x<) putchar('-'),x=-x;
if(x>) write(x/);
putchar(x%+'');
}const int M = ,State = ;
int f[M][][State],T,n,a[M],l,r,Pos[],S[State]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
inline int gcd(int x,int y){return __gcd(x,y);}
inline int lcm(int x,int y){if(x==)return y;if(y==)return x;return x*y/gcd(x,y);}
int dfs(int x,int p,int pp,bool lim){
if(!x)return (p%pp==)?():();
if(!lim&&p!=-&&pp!=-&&f[x][p][Pos[pp]]!=-)return f[x][p][Pos[pp]];
int ans=,up=lim?a[x]:;
for(int i=;i<=up;i++)ans+=dfs(x-,(p*+i)%,lcm(pp,i),lim&&a[x]==i);
if(!lim)f[x][p][Pos[pp]]=ans;
return ans;
}
inline int Solve(int x){
int len=;
while(x)a[++len]=x%,x/=;
return dfs(len,,,);
}
signed main(){
memset(f,-,sizeof(f));
for(int i=;i<=;i++)Pos[S[i]]=i;
T=read();
while(T--)l=read(),r=read(),writeln(Solve(r)-Solve(l-));
return ;
}

【数位DP】CF55D Beautiful numbers的更多相关文章

  1. [暑假集训--数位dp]cf55D Beautiful numbers

    Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...

  2. 【数位dp】Beautiful Numbers @2018acm上海大都会赛J

    目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...

  3. 洛谷 CF55D Beautiful numbers 解题报告

    CF55D Beautiful numbers 题意 \(t(\le 10)\)次询问区间\([l,r](1\le l\le r\le 9\times 10^{18})\)中能被每一位上数整除的数的个 ...

  4. cf55D. Beautiful numbers(数位dp)

    题意 题目链接 Sol 看到这种题就不难想到是数位dp了. 一个很显然的性质是一个数若能整除所有位数上的数,则一定能整除他们的lcm. 根据这个条件我们不难看出我们只需要记录每个数对所有数的lcm(也 ...

  5. CF55D Beautiful numbers (数位dp)

    题目链接 题解 一个数能被一些数整除,那么一定被这些数的\(lcm\)整除 那么我们容易想到根据\(lcm\)设状态 我们可以发现有用的\(lcm\)只有\(48\)个 那么按照一般的数位\(dp\) ...

  6. CF55D Beautiful numbers 题解

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  7. CF55D Beautiful numbers

    题目链接 题意 定义一个数字\(x\)是\(beautiful\ number\)当且仅当\(x\)可以被其十进制表示下所有非\(0\)位置的数整除. 例如\(24\)是一个\(beautiful\ ...

  8. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  9. 数位dp(Balanced Numbers )

    题意:一个数,如果满足奇数的数字出现偶数次,偶数的数字出现奇数次, 就是符合的数,注比如:12313  就满足,因为1 3出现了偶数次.2出现了奇数次 思路,对于这道题,就是状态压缩加dp: 对于一个 ...

随机推荐

  1. PAT_A1025#PAT Ranking

    Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...

  2. MVC过滤器-->ActionFilterAttribute和HandleErrorAttribute

    自定义的action过滤器  需要继承自ActionFilterAttribute 接口 OnActionExecuting:  在方法执行之前执行 OnActionExecuted:  方法的逻辑代 ...

  3. Django框架(六)—— 视图层:HttpRequest、HTTPResponse、JsonResponse、CBV和FBV、文件上传

    目录 视图层 一.视图函数 二.视图层之HttpRequest对象 三.视图层之HttpResponse对象 四.视图层之JsonResponse对象 五.CBV和FBV 六.文件上传 视图层 一.视 ...

  4. 众所周知,static修饰的成员只实例化一次,而string类型每次赋值都会重新创建一个实例,那么用static修饰string呢?

    string 类型每次实例化都会重新创建一个实例: 解释:string 类型重载了运算符 “=” ,每次 “=” 操作都是一次 “new”. static 修饰符的成员只实例化一次?? 解释:这个说法 ...

  5. Windows下Cython使用(VS2017)

    收到公众号推送文章“利用Cython为Python代码加速”后尝试在Windows平台下使用Cython,环境为Python3.5 + VS2017. 1. 简单尝试 1)新建hello.pyx文件, ...

  6. 杭电多校第三场-H-Game

    题目描述 Again Alice and Bob is playing a game with stones. There are N piles of stones labelled from 1 ...

  7. kubectl 使用token的方式连接到集群

    首先得有一个账户 kubectl create serviceaccount dashboard-admin -n kube-system #创建一个名叫dashboard-admin 命名空间在ku ...

  8. [转]在WPF中自定义控件 UserControl

    在这里我们将将打造一个UserControl(用户控件)来逐步讲解如何在WPF中自定义控件,并将WPF的一些新特性引入到自定义控件中来.我们制作了一个带语音报时功能的钟表控件, 效果如下: 在VS中右 ...

  9. Java ArrayList使用技巧 - 两个ArrayList去除重复的元素

    方法一.ArrayList中提供的removeAll方法(效率最低) List1.removeAll(mSubList); 方法二.双重循环(比方法一效率高) 双重循环分为内外两层循环,经过测试,将元 ...

  10. Batch - 忽略FORFILES “no files found” error

    ref:https://stackoverflow.com/questions/16820681/suppress-forfiles-no-files-found-error Solution: Th ...