基本的数位DP,注意记录那些状态可以用最小的空间判断出整除性。

#include <cstdio>
#include <cstring>
using namespace std; #define D(x) const int MAX_DIGIT_NUM = ; int f[MAX_DIGIT_NUM];
long long memoize[MAX_DIGIT_NUM][][][][][ << ];
bool contain[]; int to_digits(long long n)
{
int ret = ;
while (n > )
{
f[ret++] = n % ;
n /= ;
}
return ret;
} bool check(int r5, int r7, int r8, int r9, int status)
{
D(printf("%d%d%d%d %d\n", r5, r7, r8, r9, status));
memset(contain, , sizeof(contain));
int i = ;
while (status)
{
contain[i++] = status & ;
status >>= ;
}
if (contain[] && r8 % )
{
return false;
}
if (contain[] && r9 % )
{
return false;
}
if (contain[] && r8 % )
{
return false;
}
if (contain[] && r5 % )
{
return false;
}
if (contain[] && (r8 % || r9 % ))
{
return false;
}
if (contain[] && r7)
{
return false;
}
if (contain[] && r8 % )
{
return false;
}
if (contain[] && r9 % )
{
return false;
}
D(puts("***"));
return true;
} long long dfs(int digit, bool less, int r5, int r7, int r8, int r9, int status)
{
D(printf("%d\n", status));
if (digit < )
{
return check(r5, r7, r8, r9, status);
}
if (less && memoize[digit][r5][r7][r8][r9][status] != -)
{
return memoize[digit][r5][r7][r8][r9][status];
}
int limit = less ? : f[digit];
long long ret = ;
for (int i = ; i <= limit; i++)
{
int next_status = i < ? status : status | ( << (i - ));
ret += dfs(digit - , less || i < f[digit], i % , (r7 * + i) % , (r8 * + i) % , (r9 * + i) % , next_status);
}
if (less)
{
memoize[digit][r5][r7][r8][r9][status] = ret;
}
return ret;
} long long work(long long n)
{
if (n == )
{
return ;
}
int len = to_digits(n);
return dfs(len - , false, , , , , );
} int main()
{
int t;
scanf("%d", &t);
memset(memoize, -, sizeof(memoize));
while (t--)
{
long long a, b;
scanf("%I64d%I64d", &a, &b);
printf("%I64d\n", work(b) - work(a - ));
}
return ;
}

Codeforces 55D的更多相关文章

  1. Codeforces 55D (数位DP+离散化+数论)

    题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...

  2. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

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

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

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

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

  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 - 55D(数位dp,离散化)

    题目来源:http://codeforces.com/problemset/problem/55/D Volodya is an odd boy and his taste is strange as ...

  7. beautiful number 数位DP codeforces 55D

    题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...

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

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

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

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

  10. CodeForces 55D Beautiful numbers

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

随机推荐

  1. 简述frame、bounds、center

    frame是该视图在父视图坐标系统中的位置和大小.(参照父视图中的坐标系统) bounds是该视图在自身坐标系统中的位置和大小.(参照自身的坐标系统) center是该视图的中心点在父视图坐标系统中的 ...

  2. DataTable转实体

    public class ModelConvertHelper<T> where T : new() { public static IList<T> ConvertToMod ...

  3. Apple Pay

    Apple Pay运行环境:iPhone6以上设备,操作系统最低iOS9.0以上,部分信息设置需要iOS9.2以上.目前还不支持企业证书添加. 环境搭建好后可以在模拟器上面运行,xcode7.2.1+ ...

  4. Markdown语言详解

    相信大家在github上面分享了不少的项目和Demo,每次创建新项目的时候,使用的都是默认的README.md文件,也不曾对这个文件有过什么了解.但是在看到别人写的项目的README.md里面竟然有图 ...

  5. asp.net core 中的MD5加密

    尝试了很长时间,但是一直报core 5 不可用,当时就崩溃了. 但是偶然的机会 我添加了Microsoft.AspNet.Identity 之后.MD5就好用了. 估计是这个报实现了core5下的MD ...

  6. redis php扩展安装下载

    php的redis 扩展下载地址 Windows :http://windows.php.net/downloads/pecl/releases/redis/2.2.7/ 下载对应版本,一般有两个 n ...

  7. php 快速排序法

    function quicksort(array $arr = array()){ $len = count($arr); if ($len > 1) { $key = $arr[0]; $l_ ...

  8. glusterFS的常用命令 (转)

    1.       启动/关闭/查看glusterd服务 # /etc/init.d/glusterd start # /etc/init.d/glusterd stop # /etc/init.d/g ...

  9. jquery选择器(一)-基础选择器

    1. ID元素选择器 $("#btn1") 2. class元素选择器 $(".btn") 3. 标签元素选择器 $("div") 4. 全 ...

  10. cocos布局分析

    HBox和VBox布局 HBox只是一个水平布局包装类. HBox里面所有的孩子节点都会水平排列成一行 VBox仅仅是对垂直布局的一个简便的类封装. VBox把它的子节点布局在一竖列中. Layout ...