题目链接

一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数。

dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是1-9之间数的lcm。 然后这样数组就要开成20*2520*2520, 太大了, 所以我们将lcm离散, 因为1-9的lcm根本没有那么多的数, 实际上只有48个。

这题好难想...

 #include<bits/stdc++.h>
using namespace std;
#define mem1(a) memset(a, -1, sizeof(a))
#define ll long long
int digit[], len, idx[];
ll dp[][][];
int gcd(int a, int b) {
return b==?a:gcd(b, a%b);
}
int get_lcm(int a, int b) {
return a/gcd(a, b)*b;
}
void init() {
int num = ;
for(int i = ; i<=; i++) {
if(%i==)
idx[i] = num++;
}
mem1(dp);
}
ll dfs(int len, int lcm, int num, int f) {
if(!len) {
return num%lcm==;
}
if(!f&&dp[len][num][idx[lcm]]!=-)
return dp[len][num][idx[lcm]];
ll ret = , maxx = f?digit[len]:;
for(int i = ; i<=maxx; i++) {
if(i == ) {
ret += dfs(len-, lcm, (num*)%, f&&i==maxx);
} else {
int tmp = get_lcm(lcm, i);
ret += dfs(len-, tmp, (num*+i)%, f&&i==maxx);
}
}
if(!f)
return dp[len][num][idx[lcm]] = ret;
return ret;
}
ll cal(ll n) {
len = ;
while(n) {
digit[++len] = n%;
n/=;
}
return dfs(len, , , );
}
int main()
{
ll a, b, t;
init();
cin>>t;
while(t--) {
scanf("%I64d%I64d", &a, &b);
printf("%I64d\n", cal(b)-cal(a-));
}
return ;
}

codeforces 55D. Beautiful numbers 数位dp的更多相关文章

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

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

  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 —— 数位DP

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

  4. Codeforces - 55D Beautiful numbers (数位dp+数论)

    题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L- ...

  5. FZU2179/Codeforces 55D beautiful number 数位DP

    题目大意: 求  1(m)到n直接有多少个数字x满足 x可以整出这个数字的每一位上的数字 思路: 整除每一位.只需要整除每一位的lcm即可 但是数字太大,dp状态怎么表示呢 发现 1~9的LCM 是2 ...

  6. CF 55D. Beautiful numbers(数位DP)

    题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...

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

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

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

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

  9. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

随机推荐

  1. CSS技巧和犯错点总结

    4.14 CSS  background属性简写: background-position属性组合方式:[ left | center | right ] || [ top | bottom ] (组 ...

  2. 前端制作中,IE6还有必要兼容吗?

    国内市场对IE 6~7支持还有一定需求,但对于一个前端开发者,我们应该去推动这个行业向前发展,而不是一味迁就.妥协. 曾经,能够提供支持老版本 IE 是一个前端开发者的必备技能.随着移动互联网大潮来临 ...

  3. “-="的陷阱

    1.有如下代码(显示下拉框时,屏幕最大化右键菜单的显示坐标处理): 起初: Rectangle rect = System.Windows.Forms.SystemInformation.Virtua ...

  4. leetcode remove Nth Node from End python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  5. Generative Learning algorithms

    "generative algorithm models how the data was generated in order to categorize a signal. It ask ...

  6. windows命令行模式下无法打开python程序解决方法

    今天刚开始学Python,首先编写一个简单地hello world程序,想在命令行模式运行,结果出现下面: 经过一番思考,发现用cd命令可以解决这件事,看下图: 这样就解决了.

  7. android process bar 几种style

    process bar 圆形style记录 1. style="?android:attr/progressBarStyleSmall" //根据主题变颜色 2. holo 主题下 ...

  8. 你会用shuffle打乱列表吗?

    在网站上我们经常会看到关键字云(Word Cloud)和标签云(Tag Cloud),用于表明这个关键字或标签是经常被查阅的,而且还可以看到这些标签的动态运动,每次刷新都会有不一样的关键字或便签,让浏 ...

  9. JavaEE Tutorials (18) - Java EE平台安全介绍

    18.1Java EE安全概述278 18.1.1简单的应用安全演示279 18.1.2安全机制特性281 18.1.3应用安全特点28118.2安全机制282 18.2.1Java SE安全机制28 ...

  10. oracle解锁表

    select b.owner,b.object_name,a.session_id,a.locked_mode,c.serial#,c.sid||','||c.serial# from v$locke ...