基本的数位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. JS验证URL正则

    方法一: function fIsUrL(sUrl) { var sRegex = '^((https|http|ftp|rtsp|mms)?://)' + '?(([0-9a-z_!~*\'().& ...

  2. MongoDB创建数据库和集合命令db.createCollection详解(转)

    切换/创建数据库 use yourDB;  当创建一个集合(table)的时候会自动创建当前数据库 完整的命令如下:db.createCollection(name, {capped: <Boo ...

  3. 四种生成和解析XML文档的方法详解(介绍+优缺点比较+示例)

    众所周知,现在解析XML的方法越来越多,但主流的方法也就四种,即:DOM.SAX.JDOM和DOM4J 下面首先给出这四种方法的jar包下载地址 DOM:在现在的Java JDK里都自带了,在xml- ...

  4. Java-java中无符号类型的处理

    在Java中,不存在Unsigned无符号数据类型,但可以轻而易举的完成Unsigned转换. 方案一:如果在Java中进行流(Stream)数据处理,可以用DataInputStream类对Stre ...

  5. [转] 安装DotNetCore.1.0.1-VS2015Tools.Preview2.0.2出现0x80072f8a未指定的错误

    原文地址:安装DotNetCore.1.0.1-VS2015Tools.Preview2.0.2出现0x80072f8a未指定的错误 最近DotNetCore更新到了1.0.1,Azure tools ...

  6. 【11-01】Sublime text 学习笔记

    >>>快捷键 CTRL+P ->根据文件名打开文件 “# 标识”“:行号” Ctrl+Shift+P -> 打开Package Control Ctrl+R ->查 ...

  7. php 关于时区 date gmdate date_default_timezone_set/get 终极答疑

    关于GMT和UTC时间? GMT+0800 Greenwich: [gri:nitf], 格林威治/格林尼治.是英国伦敦泰晤士河附近的一个小镇 Mean: adj. 自私的; n. 平均.. he i ...

  8. JQ分页功能

    HTML <div id='page'></div> <div id='con'></div> CSS span{width: 60px;height: ...

  9. 《Effective C++》第三版笔记

    阅读此笔记前,请先阅读 <Effective C++>第二版笔记  和  <More Effective C++>笔记 这里只记录与上面笔记不同的条款,主要是 "面对 ...

  10. glusterFS的常用命令 (转)

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