【数位DP】CF55D Beautiful numbers
$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的更多相关文章
- [暑假集训--数位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 ...
- 【数位dp】Beautiful Numbers @2018acm上海大都会赛J
目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...
- 洛谷 CF55D Beautiful numbers 解题报告
CF55D Beautiful numbers 题意 \(t(\le 10)\)次询问区间\([l,r](1\le l\le r\le 9\times 10^{18})\)中能被每一位上数整除的数的个 ...
- cf55D. Beautiful numbers(数位dp)
题意 题目链接 Sol 看到这种题就不难想到是数位dp了. 一个很显然的性质是一个数若能整除所有位数上的数,则一定能整除他们的lcm. 根据这个条件我们不难看出我们只需要记录每个数对所有数的lcm(也 ...
- CF55D Beautiful numbers (数位dp)
题目链接 题解 一个数能被一些数整除,那么一定被这些数的\(lcm\)整除 那么我们容易想到根据\(lcm\)设状态 我们可以发现有用的\(lcm\)只有\(48\)个 那么按照一般的数位\(dp\) ...
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- CF55D Beautiful numbers
题目链接 题意 定义一个数字\(x\)是\(beautiful\ number\)当且仅当\(x\)可以被其十进制表示下所有非\(0\)位置的数整除. 例如\(24\)是一个\(beautiful\ ...
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- 数位dp(Balanced Numbers )
题意:一个数,如果满足奇数的数字出现偶数次,偶数的数字出现奇数次, 就是符合的数,注比如:12313 就满足,因为1 3出现了偶数次.2出现了奇数次 思路,对于这道题,就是状态压缩加dp: 对于一个 ...
随机推荐
- opencv 打开摄像头(c++)
1,打开视频文件 2,打开IP摄像头 读取大华摄像头 大华的网络摄像头编号:DH-IPC-HFW1225M-I1-0600B,用的是RTSP协议. "rtsp://admin:dahua@1 ...
- python-selenium -- 弹出框处理
弹出框有两种:页面弹出框(可定位元素能操作).Windows弹出框(不能直接定位) 一.页面弹出框 等待弹出框出现之后,定位弹出框,操作其中元素 如: driver = webdriver.Chrom ...
- 访问nginx时验证密码
只允许1.2.3.4这个IP访问我们的站点,拒绝所有其他IP的访问. server { listen 80; server_name www.example.com; satisfy any; all ...
- AutoFac mvc和WebAPI 注册Service (接口和实现)
AutoFac mvc和WebAPI 注册Service (接口和实现) 1.准备组件版本:Autofac 3.5.0 Autofac.Integration.Mvc 3.3.0.0 (I ...
- 前端 css 进阶
内容目录: 1.css盒子模型 2.浮动 float 3.溢出 overflow 4.定位 position 5. z-index 6.opacity 1.css盒子模型 margin:用来调节盒子与 ...
- centos7.x部署php7.0、mysql
1.安装httpd yum install httpd systemctl start httpd.service #启动命令 systemctl stop httpd.service #停止命令 s ...
- html中没有不能随意嵌套的标签
在HTML里有几个元素是比较特别的:<ul>.<ol>.<dl>.<table>,它们的子一层必须是指定元素,<ul>.<ol> ...
- Java中volatile关键字及其作用是什么?
在 Java 多线程中如何保证线程的安全性?那我们可以使用 Synchronized 同步锁来给需要多个线程访问的代码块加锁以保证线程安全性.使用 synchronized 虽然可以解决多线程安全问题 ...
- [JZOJ6355] 【NOIP2019模拟】普 24/100
题目 题目大意 给你一个序列,对于所有\(k\in [1,n]\),求长度为\(k\)的子序列的最大权值,权值为\(a_1-a_2+a_3-...\pm a_k\) 思考历程 这题显然可以背包对吧-- ...
- delphi xe10 网络文件传送
//网络传送文件(类似Server/Client) TTetheringManager|设备管理.TTetheringAppProfile|文件发送 待补充