题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数。

注意离散化,为了速度更快需存入数组查找。

不要每次memset,记录下已有的长度下符合条件的个数。

数位dp肯定是从高位到低位。

记录数字已经有多大,还有lcm,递归传下去。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
lon dp[][][],index[];//
vector<lon> ls; lon gcd(lon x,lon y)
{
if(x<y)swap(x,y);
for(;;)
{
lon rem=x%y;
if(rem==)return y;
x=y;
y=rem;
}
} lon lcm(lon x,lon y)
{
return x*y/gcd(x,y);
} void getid()
{
for(lon i=;i<ls.size();++i)
{
index[ls[i]]=i;
}
} void lsh()
{
for(lon i=;i<pow(,);++i)
{
lon cur=;
for(lon j=;j<;++j)
{
if(i&(<<j))cur=lcm(cur,j+);
}
ls.push_back(cur);
}
sort(ls.begin(),ls.end());
ls.erase(unique(ls.begin(),ls.end()),ls.end());
getid();
} lon dfs(lon pos,lon cur,lon prelcm,lon limit,string &str)
{
if(pos==str.size())return cur%prelcm==;
if(!limit&&dp[str.size()-pos-][cur][index[prelcm]]!=-)return dp[str.size()-pos-][cur][index[prelcm]];
lon res=;
lon up=limit?str[pos]-'':;
for(lon i=;i<=up;++i)
{
lon curlcm=prelcm;
if(i)curlcm=lcm(i,curlcm);
res+=dfs(pos+,(cur*+i)%,curlcm,limit&&str[pos]-''==i,str);
}
if(!limit)dp[str.size()-pos-][cur][index[prelcm]]=res;
return res;
} lon work(string &str)
{
return dfs(,,,,str);
} bool chk(string &str)
{
lon num=,curlcm=;
for(lon i=;i<str.size();++i)
{
num=(num*+str[i]-'')%;
if(str[i]!='')curlcm=lcm(curlcm,str[i]-'');
}
return num%curlcm==;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
cin>>casenum;
lsh();
memset(dp,-,sizeof(dp));
for(lon time=;time<=casenum;++time)
{
string ll,rr;
cin>>ll>>rr;
lon res=work(rr)-work(ll);
if(chk(ll))++res;
cout<<res<<endl;
}
return ;
}

codeforces 55d//Beautiful numbers// Codeforces Beta Round #51的更多相关文章

  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 55D Beautiful numbers

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

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

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

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

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

  7. CodeForces 55D Beautiful numbers(数位dp+数学)

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:一个美丽数就是可以被它的每一位的数字整除的数. 给定一个区间,求美丽数的个数. 显然这是一道 ...

  8. CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)

    题意 求[X,Y]区间内能被其各位数(除0)均整除的数的个数. CF 55D 有些时候因为问题的一些"整体性"而导致在按位统计的过程中不能顺便计算出某些量,所以只能在枚举到最后一位 ...

  9. CodeForces 55D Beautiful numbers(数位dp)

    数位dp,三个状态,dp[i][j][k],i状态表示位数,j状态表示各个位上数的最小公倍数,k状态表示余数 其中j共有48种状态,最大的是2520,所以状态k最多有2520个状态. #include ...

随机推荐

  1. Python: ord()函数

    ch() , unichr() , ord() ①chr()函数用一个范围在range(256)内的整数作参数,返回一个对应的字符. >>>chr(65) 'A' ②unichr() ...

  2. OVS

    基于 OpenvSwitch的OpenFlow实践 Open vSwitch 概述 OpenvSwitch(简称OVS)是由NiciraNetworks主导的,运行在虚拟化平台(例如 KVM,Xen) ...

  3. Linux基础命令---chmod

    chmod 改变文件或者目录的权限,可以用数字或者字母来标识权限.在数字模式下:0,代表没有权限:1,代表可执行:2,代表可读:4,代表可写:多个权限可以相加.在字符模式下:x,代表执行:r,代表读: ...

  4. 学习Linux的正确姿势

    学习Linux的正确姿势 端正学习态度1.Linux不等于骇客(or Cracker).当然众所周知很多“黑客工具”都是Linux平台上的,我帮助过很多Linux小白发现他们殊途同归都是朝着类似Air ...

  5. MySQL数据库----存储引擎

    什么是存储引擎? 存储引擎说白了就是如何存储数据.如何为存储的数据建立索引和如何更新.查询数据等技术的实现方法.因为在关系数据库中数据的存储是以表的形式存储的,所以存储引擎也可以称为表类型(即存储和操 ...

  6. [转] Oracle学习之创建数据库(新建实例)

    由于项目需求,在本机中开发,需要新建oracle数据库实例,亲测可以. 出处:http://blog.csdn.NET/luiseradl/article/details/6972217 http:/ ...

  7. 如何在 Linux 中挂载 ISO 文件

    在 Windows 中,我们常常使用 Daemon Tools 和 Virtual CloneDrive 等虚拟光驱软件挂载光盘镜像,下面我们一起来学习在 Linux 中如何挂载 ISO 文件. 在 ...

  8. centos 安装最新稳定版本docker

    直接yum安装的docker版本是 : docker --versionDocker version 1.12.6, build 85d7426/1.12.6 一些新特性需要安装最新的稳定版本 国内可 ...

  9. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 1 章 答案

    判断对错1.计算机科学是计算机的研究.2.CPU 是计算机的“大脑”.3.辅助存储器也称为 RAM.4.计算机当前正在处理的所有信息都存储在主存储器中.5.语言的语法是它的意思,语义是它的形式.6.函 ...

  10. jQuery 源码分析:当 selector 传来一个函数时,怎么进行处理?

    本文章为 0.9 版本,将会在稍后润色更新.本文使用的 jQuery 版本为 3.4.0 我们知道使用 $ 操作符时,可以往里面塞很多类型的参数,字符串,对象,函数...,jQuery 会根据不同的参 ...