【数位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: 对于一个 ...
随机推荐
- C#WinForm 窗体回车替换Tab
/// <summary> /// 回车切换控件 /// </summary> /// <param name="sender"></pa ...
- 68.最大k乘积问题 (15分)
C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容:设I是一个n位十进制整数.如果将I划分为k段,则可得到k个整数.这k个整数的乘积称为I的一个k乘积.试设计一个算法,对于给定的I和 ...
- jmeter-测试webservice接口
测试webservice接口(soap类型接口) 一.webservice协议的本质 一个经过封装的post类型的HTTP请求 Web service一般就是用SOAP协议通过HTTP来调用它,其实他 ...
- usb-host与外设通信(二)
本文是接着上一篇的的usb-host与外设通信(一)接着写的 3.枚举设备 当你的程序运行时,如果应用程序对当前连接的USB设备都感兴趣的,程序可以枚举所以当前的设备.使用getDeviceList( ...
- 转载:mysql sql_safe_updates 分析
今天看到一个很实用的功能,mysql_safe_updates. 只是对功能做了转载,具体原理可以看一下 delete from table t where true ; update t set c ...
- windows版nginx+ftp实现图片服务器的搭建
配置图片服务器的一部分参数 resource.properties: #FTP\u76f8\u5173\u914d\u7f6e #FTP\u7684ip\u5730\u5740 FTP_ADDRESS ...
- layerui ios不适应问题
.admin-main {-webkit-overflow-scrolling: touch; overflow: scroll; position: absolute; left: 0; top: ...
- Struts2开发环境搭建
eclipse配置struts2开发环境: 1.导入jar包:复制Struts\apps\struts2-blank\WEB-INF\lib下的所有jar包到当前项目的lib文件夹下 2.在web.x ...
- Codeigniter Session: Configured save path is not a directory
Codeigniter 3.x Message: Session: Configured save path '' is not a directory, doesn't exist or canno ...
- 揭秘!2周实现上云上市,阿里云SaaS上云工具包如何打造新云梯?
提到“上云”,很多人会理解成上IaaS,比如买一些计算.存储和网络云产品,把自己的应用系统部署上去.这的确是通常意义的上云.但对SaaS而言,需要从产品.商业.服务,三个维度考虑SaaS伙伴和客户的痛 ...