基本的数位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. 用C语言将搜狗输入法词库转换成QQ拼音输入法词库

    搜狗输入法词库格式: 'ni'kan'xia 你看下 'ni'kan'xia'gai'hou 你看下改后 'ni'kan'xing'ma 你看行吗 'ni'kan'zen'me'yang 你看怎么样 ...

  2. iOS- storyboard this class is not key value coding-compliant for the key xxx

    如图: 在使用storyboard的时候出现此问题,主要是因为给storybroad中的view拖线的时候,有时不小心线拖错了,或者再次拖线导致代码中控件的名字与之前拖线时定义的名字不同导致的. 解决 ...

  3. char,short ,int ,long,long long,unsigned long long数据范围

    from:http://www.cnblogs.com/A123456A/archive/2013/01/25/2876634.html char,short ,int ,long,long long ...

  4. yaf自动加载文件

    models下面的文件 例如:Article.php 类名必须是:ArticleModel 调用时:$article_models = new ArticleModel(); library下面的文件 ...

  5. Vue 入门指南 JS

    Vue 入门指南 章节导航 英文:http://vuejs.org/guide/index.html 介绍 vue.js 是用来构建web应用接口的一个库 技术上,Vue.js 重点集中在MVVM模式 ...

  6. 从头开始写框架(一):浅谈JS模块化发展

    博客申请下来已经过去一个月了,一直不知道写点什么,毕竟我的文笔不是很好orz. 不过既然申请下来了,不写点什么总是觉得很可惜.正好最近在自己写框架,就把自己的进程和一些心得体会分享出来吧. 写在前面: ...

  7. height:100%和height:auto的区别

    一直不明白height:100%和height:auto的区别,最近在制作前端页面时都用了height:100%;overflow:hidden; ,可是有些浏览器出现莫名的奇妙的问题,但换成heig ...

  8. 绿书模拟day10 单词前缀

    [题目描述]一组单词是安全的,当且仅当不存在一个单词是另一个单词的前缀,这样才能保证数据不容易被误解,现在你手上有一个单词集合s,你需要计算有多少个自己是安全的.注意空集永远是安全的.[输入格式]第一 ...

  9. INSTALL_FAILED_INSUFFICIENT_STORAGE(转发)

    [2012-06-19 14:06:47 - Icontacts] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE[2012-06-19 ...

  10. Net上传附件大小控控值(转)

    Server Error 404 – File or directory not found. The resource you are looking for might have been rem ...