原题链接

虽然依旧是套模板,但是因为我太弱了,不会建状态,所以去看了题解。。

这里就直接引用我看的题解吧,写的不错的。

题解

//我的代码
#include<cstdio>
#include<cstring>
using namespace std;
const int mod = 2520;
const int N = mod + 10;
typedef long long ll;
int a[20], lc[N], l;
ll f[20][N][50];
inline ll re()
{
ll x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
int gcd(int x, int y)
{
if (!y)
return x;
return gcd(y, x % y);
}
int LCM(int x, int y)
{
if (!y)
return x;
return x / gcd(x, y) * y;
}
ll dfs(int pos, int nw, int lcm, int lm)
{
if (pos < 0)
return nw % lcm ? 0 : 1;
if (!lm && f[pos][nw][lc[lcm]] > -1)
return f[pos][nw][lc[lcm]];
int i, k = lm ? a[pos] : 9;
ll s = 0;
for (i = 0; i <= k; i++)
s += dfs(pos - 1, (nw * 10 + i) % mod, LCM(lcm, i), lm && i == a[pos]);
if (!lm)
return f[pos][nw][lc[lcm]] = s;
return s;
}
ll calc(ll x)
{
int k = 0;
do
{
a[k++] = x % 10;
x /= 10;
} while (x > 0);
return dfs(k - 1, 0, 1, 1);
}
int main()
{
int i, t;
ll n, m;
for (i = 1; i * i <= mod; i++)
if (!(mod % i))
{
lc[mod / i] = ++l;
lc[i] = ++l;
}
memset(f, -1, sizeof(f));
t = re();
for (i = 1; i <= t; i++)
{
n = re();
m = re();
printf("%I64d\n", calc(m) - calc(n - 1));
}
return 0;
}

Codeforces55D Beautiful numbers的更多相关文章

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

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

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

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

  3. CodeForces 55D Beautiful numbers

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

  4. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

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

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

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

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

  7. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

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

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

  9. Codeforces Beta Round #51 D. Beautiful numbers

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

随机推荐

  1. CAP与Base理论

    分布一致性的提出 在分布式系统中要解决的一个重要问题就是数据的复制.在我们的日常开发经验中,相信很多开发人员都遇到过这样的问题:假设客户端C1将系统中的一个值K由V1更新为V2,但客户端C2无法立即读 ...

  2. frambuffer 相关函数理解

    1. framebuffer_alloc()功能是向内核申请一段大小为sizeof(struct fb_info) + sizeprivate的空间,其中sizeprivate的大小代表设备的私有数据 ...

  3. linux 系统 网卡 ethX没有显示IP的处理方式

    1 临时方式 ifconfig  设备名 IP 地址 (ifconfig eth0  192.168.1.117) 设置好之后马上生效,不需要重启网卡服务(千万别重启网卡服务,不然刚刚设置的又没有了) ...

  4. mongo副本集设置主库权重,永远为主

    mongo副本集设置主库权重,即使主库宕机了再重启也还是主库. cfg = rs.conf()     ------->(查看序列)cfg.members[0].priority = 1 (设置 ...

  5. sqlite 时间戳转时间

    ), 'unixepoch','localtime') from messages where data != '' order by timestamp desc 官方eg: Examples Co ...

  6. 2.3、CDH 搭建Hadoop在安装(安装Cloudera Manager Server)

    第3步:安装Cloudera Manager Server 在此步骤中,您将在Cloudera Manager主机上安装JDK和Cloudera Manager Server软件包. 安装Cloude ...

  7. pip安装离线包

    离线包从pypi.org下载 pip download  -r requirements.txt  -d  /tmp/paks/ 在linux下       1.下载指定的包到指定文件夹.       ...

  8. Docker容器进入-命令行只显示-bash-4.1#

    bash-4.1# cp /etc/skel/.bash* /root/ bash-4.1# su [root@4a841f025562 ~]# [root@4a841f025562 ~]# [roo ...

  9. TOJ 4829: 计算器的改良

    Python写法! 传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4829 描述 N ...

  10. python指针

    class ListNode: def __init__(self, x): self.val = x self.next = None就两个属性 value 和 next,因为单节点默认next是没 ...