基本的数位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. Linux系统改变ls文件和文件夹颜色方法

    本人之前就针对蓝色文件夹的颜色  我是这样修改的:    cp /etc/DIR_COLORS   ~/.dir_colors vim   ~/.dir_colors   , 将DIR 01;33   ...

  2. C#技术漫谈之垃圾回收机制(GC)(转)

    GC的前世与今生 虽然本文是以.NET作为目标来讲述GC,但是GC的概念并非才诞生不久.早在1958年,由鼎鼎大名的图林奖得主John McCarthy所实现的Lisp语言就已经提供了GC的功能,这是 ...

  3. 只允许wheel组到用户才能使用 su命令

    su只是切换到root用户, 不改变当前目录: su - 切换到root和改变目录到/root 修改用户到组: usermod gpasswd wheel组相当于windows的 Administra ...

  4. C语言内存管理(转)

    伟大的Bill Gates 曾经失言: 640K ought to be enough for everybody — Bill Gates 1981 程序员们经常编写内存管理程序,往往提心吊胆.如果 ...

  5. 用友android

    获取token要改 value要改 不用通配符 直接双引号

  6. 让ie浏览器支持html5新标签的解决方法(使用html5shiv)

    没估计错的话旧版浏览器都是不识别这些新增的标签所以都是用行内元素来处理解决的,所以,有一个解决办法的突破口就是让它变成块状元素就不会处于同一行了,这样在新旧浏览器都是可以显示同样的效果,再者就是让浏览 ...

  7. Nginx如何隐藏index.html

    我要隐藏目录下的index.html,修改Nginux配置如下: 1.修改文档顺序 index  index.html index.php 2.开启目录流量 在server或location 段里添加 ...

  8. Ubuntu10.04下安装Ns2的一系列错误及解决方案

    安装之前改一下nam1.11下的agent.h文件73行 Null改为0 第一个错误: xxx configuration: Syntax error: Unterminated quoted str ...

  9. 如何打开xip格式的xcode安装包

    解决方法如下: 1.保证存储空间 20G 2.去除解压验证 xattr -d com.apple.quarantine Xcode_8_beta.xip 3.双击解压 详见: 从官网下载的 xcode ...

  10. 网络编程3-URL编程(URL)

    1.URL(Uniform Resource Locatior) 统一资源占位符,表示Intenet上某一资源的地址 2.URL的组成部分 传输协议:主机名:端口号:文件名 例:http://192. ...