$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. hibernate 中createQuery与createSQLQuery两者区别

    hibernate 中createQuery与createSQLQuery两者区别是:前者用的hql语句进行查询,后者可以用sql语句查询前者以hibernate生成的Bean为对象装入list返回, ...

  2. 记录阿里云ECS搭建Wordpress(Centos7+LAMP)

    占位 改变wordpress文件夹属主属组 cd /var/www/html chown -R apache:apache wordpress <VirtualHost *:> Docum ...

  3. MyEclipse中最常用的快捷键大全

    1. [ALT+/]    此快捷键为用户编辑的好帮手,能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类.方法和属性的名字时,多体验一下[ALT+/]快捷键带来的好处吧. 2. [C ...

  4. python实现马赛克拼图!

    python实现马赛克拼图 直接上代码! 代码如下: #!/usr/local/bin/python3#  --*-- coding:utf8 --*-- import getoptimport sy ...

  5. 移动端新建html页面

    这是一些头部设置 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  6. hud 3183

    题意:给出n个数字的字符串,要求你删除m个数字后,得到的数字最小. 分析:删除m个,就是选n-m个,而且,选的第一个数,肯定在(0—(n-m-1))中,第二个就在(第一个的下一位—(n-m-2)中.就 ...

  7. hdu 6435 /// 状压

    题目大意: 给定 n m k 为 n种主武器 m种副武器 武器有k种属性 接下来n行 先给定当前主武器的综合分s1 再给定k种属性的值 接下来m行 先给定当前副武器的综合分s2 再给定k种属性的值 要 ...

  8. 3306端口被占用导致MySQL无法启动

    报错:mysql服务无法启动1067 发现WINDOWS下面没有MYSQL的服务在MYSQL的安装目录bin下面安装MYSQL服务:C:\Program Files\MySQL\MySQL Serve ...

  9. python的magic methods

    https://pycoders-weekly-chinese.readthedocs.io/en/latest/issue6/a-guide-to-pythons-magic-methods.htm ...

  10. BBS论坛 home主页与个人站点主页

    五.Home主页与个人站点主页 home首页代码: # views.py视图函数部分代码def home(request): # 将数据库中的所有文章展示到主页 article_list = mode ...