[Codeforces-div.1 55D] Beautiful numbers

试题分析

还是离散化。。。\(f_{i,j,k}\)表示i位,gcd为j,余数为k。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm> using namespace std;
#define LL long long inline LL read(){
LL x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const LL MAXN = 100010;
const LL INF = 2147483600; LL sta[MAXN+1]={0,1,2,3,4,5,6,7,8,9,10,12,14,15,18,20,21,24,28,30,35,36,40,42,45,56,60,63,70,72,84,90,105,120,126,140,168,180,210,252,280,315,360,420,504,630,840,1260,2520},top; inline LL gcd(LL a,LL b){
return (!b?a:gcd(b,a%b));
}
inline LL LCM(LL a,LL b){
if(!a||!b) return b|a;
return a*b/gcd(a,b);
}
LL f[21][50][2600];
LL cnt; LL str[MAXN+1],num[MAXN+1]; inline LL dfs(LL i,LL j,LL k,LL g){
if(i==0) return j&&(k%sta[j]==0);
if(!g && ~f[i][j][k]) return f[i][j][k];
LL ans=0; for(LL l=0;l<=(g?str[i]:9);l++){
LL x=LCM(sta[j],l);
ans+=dfs(i-1,num[x],(k*10%2520+l)%2520,g&(str[i]==l));
} return (g?ans:f[i][j][k]=ans);
}
inline LL init(LL x){
cnt=0; while(x) str[++cnt]=x%10,x/=10;
return dfs(cnt,0,0,1);
}
LL T; int main(){
//freopen(".in","r",stdin);
memset(f,-1,sizeof(f));
T=read(); for(LL i=1;i<49;i++) num[sta[i]]=i;
while(T--){
LL L=read(),R=read(); LL ans=0;
ans+=init(R); ans-=init(L-1);
printf("%lld\n",ans);
}
return 0;
}

[Codeforces-div.1 55D] Beautiful numbers的更多相关文章

  1. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  2. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  3. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  5. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  6. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  7. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

  8. CF 55D - Beautiful numbers(数位DP)

    题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...

  9. 【数位dp】CF 55D Beautiful numbers

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

随机推荐

  1. Spring4+SpringMVC+MyBatis整合思路(山东数漫江湖)

    1.Spring框架的搭建 这个很简单,只需要web容器中注册org.springframework.web.context.ContextLoaderListener,并指定spring加载配置文件 ...

  2. 【洛谷 P2783】 有机化学之神偶尔会做作弊 (双联通分量)

    题目链接 可能是除了<概率论>的最水的黑题了吧 用\(Tarjan\)缩点(点双联通分量),然后就是树上两点之间的距离了,跑\(LCA\)就好了. #include <cstdio& ...

  3. WordPress在nginx服务器伪静态

    server { listen 80; root /var/www/xxx; server_name www.xxx.com; access_log /var/log/www/xxx.log main ...

  4. mssql手工注入2

    --+ 先说一些函数的说明: substring(str,start,len) 截取字符串的作用,第一个参数为要截取的字符串,第二个参数为从哪里开始截取,第三个参数为截取的长度 ascii(char) ...

  5. MSF爆破MSSQL

    show options: msf auxiliary(scanner/mssql/mssql_login) > show options Module options (auxiliary/s ...

  6. Professional Linux Kernel Architecture 笔记 —— 中断处理(Part 2)【转】

    转自:http://blog.163.com/vic_kk/blog/static/494705242010719483774/ Table of Contents 1 中断 1.1 中断的类型 1. ...

  7. 自己动手实现arm函数栈帧回溯【转】

    转自:http://blog.csdn.net/dragon101788/article/details/18668505 内核版本:2.6.14 glibc版本:2.3.6 CPU平台:arm gl ...

  8. linux===给新手的 10 个有用 Linux 命令行技巧(转)

    本文转自:http://www.codeceo.com/article/10-linux-useful-command.html?ref=myread 仅用作学习交流使用.如有侵权,立删 我记得我第一 ...

  9. write-ups

    https://github.com/MarioVilas/write-ups https://github.com/Deplorable-Mountaineer/Robot_Dynamite htt ...

  10. 005 JAVA多线程和并发基础面试问答(转载)

    原文链接:http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-answers/ 多线程和并发问题是Ja ...