hdu 5564 Clarke and digits
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5564
-----------------------------------------------------------------------------------------
刚读完题目感觉像是数位DP,然而仔细看了数据范围后感觉很不可做。
与数位DP题目对比可以发现 此题数据范围要大一些,却没有对每一位进行限制
于是便可以愉快地进行矩阵乘法优化DP啦
如果矩阵构造(将递推式转换为矩阵形式)还不熟练的话 可以参考
挑战程序设计竞赛(第2版) 3.4.2节
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 1e9 + , L = + ;
int t, l, r, m;
long long raw[L][L], tmp[L][L], a[L][L], b[L][L], f[L];
long long ans1, ans2;
void mul(long long A[L][L], long long B[L][L])
{
memset(tmp, , sizeof tmp);
for(int i = ; i < L; ++i)
for(int j = ; j < L; ++j)
{
for(int k = ; k < L; ++k)
tmp[i][j] += A[i][k] * B[k][j] % mod;
tmp[i][j] %= mod;
}
for(int i = ; i < L; ++i)
for(int j = ; j < L; ++j)
A[i][j] = tmp[i][j];
}
long long solve(int lim)
{
if(!lim)
return ;
if(lim == )
return ;
lim -= ;
for(int i = ; i < L; ++i)
for(int j = ; j < L; ++j)
a[i][j] = b[i][j] = raw[i][j];
while(lim)
{
if(lim & )
mul(a, b);
mul(b, b);
lim >>= ;
}
long long tans = ;
for(int i = ; i < L; ++i)
tans += a[][i] * f[i] % mod;
return tans % mod;
}
int main()
{
for(int i = ; i <= ; ++i)
f[i * + i % ] = ;
f[] = ;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &l, &r, &m);
memset(raw, , sizeof raw);
for(int i = ; i <= ; ++i)
for(int j = ; j <= ; ++j)
if(i + j != m)
{
for(int k = ; k < ; ++k)
{
raw[i * + (k * + i) % ][j * + k] = ;
if((k * + i) % == )
++raw[][j * + k];
}
}
raw[][] = ;
ans1 = solve(l - );
ans2 = solve(r);
printf("%lld\n", (ans2 - ans1 + mod) % mod);
}
return ;
}
hdu 5564 Clarke and digits的更多相关文章
- hdu 5564 Clarke and digits 矩阵快速幂优化数位dp
Clarke and digits Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5564 Clarke and digits 状压dp+矩阵加速
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5564 题意: 求长度在[L,R]范围,并且能整除7的整数的总数. 题解: 考虑最原始的想法: dp[ ...
- 【HDOJ】5564 Clarke and digits
DP+快速矩阵幂.注意base矩阵的初始化,不难. /* 5564 */ #include <iostream> #include <string> #include < ...
- HDU 5564:Clarke and digits 收获颇多的矩阵快速幂 + 前缀和
Clarke and digits Accepts: 16 Submissions: 29 Time Limit: 5000/3000 MS (Java/Others) Memory Limi ...
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- hdu 5565 Clarke and baton 二分
Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 5563 Clarke and five-pointed star 水题
Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 5464 Clarke and problem dp
Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
随机推荐
- Mac005--VS&webstorm前端开发工具安装
Mac--Visual studio Code工具安装(企业常用) 安装网址:https://code.visualstudio.com/download 设置格式: 1.配置工作区与终端字体大小 常 ...
- jQuery 动态添加、删除css样式
1.addClass css中: <style type="text/css"> .chColor {background: #267cb7;color:w ...
- Node.js实战5:操作系统与命令行。
Nodejs有一些内置的方法可以查询操作系统信息: 如: process.arch获取到系统是32位还是64位, process.platform可获取系统的类型. 例程: console.log(p ...
- 报错: no such table:django_session解决方式
如果出现这个错误 “no such table:django_session” 这个错误跟Session的机制有关, 既然要从Web服务器端来记录用户信息, 那么一定要有存放用户session id对 ...
- 数据导出 写入到excle文件
import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.poi ...
- 攻防世界--dmd-50
测试文件:https://adworld.xctf.org.cn/media/task/attachments/7ef7678559ea46cbb535c0b6835f2f4d 1.准备 获取信息 6 ...
- css day2
外观属性 color:文本颜色 用于定义文本的颜色 1.预定义的颜色值,如red.green.blue等 2.十六进制,如#FF0000.#FF6600.#29D794等.十六进制是最常用的定义颜色的 ...
- MySQL--17 配置binlog-server 及中间件
目录 配置binlog-server MySQL中间件Atlas Atlas管理接口 配置binlog-server 修改mha配置文件 [root@mysql-db03 ~]# vim /etc/m ...
- ElasticSearch 单台服务器部署多个节点
转载:https://www.cnblogs.com/wxw16/p/6160186.html 一般情况下单台服务器只会部署一个ElasticSearch node,但是在学习过程中,很多情况下会需要 ...
- MyCat(1.2)Mycat的安装
[0]基本环境 OS:CentOS7.5 Software envireonment:JDK1.7.0 Master Software:Mycat1.6.5 Linux Client:CRT 8.0 ...