Codeforces 55D
基本的数位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的更多相关文章
- Codeforces 55D (数位DP+离散化+数论)
题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 55D(数位dp,离散化)
题目来源:http://codeforces.com/problemset/problem/55/D Volodya is an odd boy and his taste is strange as ...
- beautiful number 数位DP codeforces 55D
题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...
- CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)
题意 求[X,Y]区间内能被其各位数(除0)均整除的数的个数. CF 55D 有些时候因为问题的一些"整体性"而导致在按位统计的过程中不能顺便计算出某些量,所以只能在枚举到最后一位 ...
- CodeForces 55D Beautiful numbers(数位dp+数学)
题目链接:http://codeforces.com/problemset/problem/55/D 题意:一个美丽数就是可以被它的每一位的数字整除的数. 给定一个区间,求美丽数的个数. 显然这是一道 ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- Mongodb的Samus驱动
最近开始学习Mongodb方面的东西.. 看到有很多博主都说MongoDB的第三方驱动 Samus 对Linq的支持比较好..能够降低学习的成本..所以就想从这里开始.. 但是弊端在我学习了一半的时候 ...
- thinkphp伪静态(url重写)
1. 服务器开启url_rewrite功能,linux空间的php虚拟主机只需要开启apache的mod_rewriet,如果是iis6.0就要安装ISAPI Rewrite模块,apache只要开启 ...
- linux程序设计1
a.out 的意思是 assembler output,即汇编输出. C语言的头文件一般位于 /usr/include/ 目录下,而依赖于特定 Linux 版本的头文件通常可在目录 /usr/incl ...
- mysql 总结二(自定义函数)
本质:mysql内置函数的一种扩展,本质上与mysql内置函数一样. 函数必要条件: @1:参数(非必备): @2:返回值: 模板: create function function_name ret ...
- NFS服务器简介
1.NFS为Network File System(网络文件系统):不同机器不同的操作系统可以彼此共享数据文件. NFS的配置简单,启动remote procedure call(RPC, ...
- RelativeLayout布局
RelativeLayout用到的一些重要的属性: 第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中android:layout_center ...
- 认识ATL窗口
这是一个相当于“Hello world!”的任务,作为认识ATL,考查了其运作流程与机制. 环境:VS2008 创建:新建-项目-Win32项目-添加公用头文件用于(选择ATL). PS:注意新建项目 ...
- 网络编程2-UDP编程(DatagramSocket)
1.传输层有两个协议,一个是tcp协议,另一个是udp协议,tcp协议通过socket编程.udp通过数据报编程. UDP协议: (1)将数据.源地址.目的地址 封装成数据包,不需要建立链接 (2)每 ...
- mysql python image
连接mysql数据库: cnx = mysql.connector.connect(user='joe', database='test') Connector/Python参数列表 Argument ...
- Redis学习笔记七:独立功能之排序
sort 命令可以对列表键.集合键或有序集合键的值进行排序.sort 命令并不修改数据库值,只是输出有序. 127.0.0.1:6379> rpush numbers 9 8 7 6 1 2 3 ...