题目链接

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的更多相关文章

  1. hdu 5564 Clarke and digits 矩阵快速幂优化数位dp

    Clarke and digits Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. HDU 5564 Clarke and digits 状压dp+矩阵加速

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5564 题意: 求长度在[L,R]范围,并且能整除7的整数的总数. 题解: 考虑最原始的想法: dp[ ...

  3. 【HDOJ】5564 Clarke and digits

    DP+快速矩阵幂.注意base矩阵的初始化,不难. /* 5564 */ #include <iostream> #include <string> #include < ...

  4. HDU 5564:Clarke and digits 收获颇多的矩阵快速幂 + 前缀和

    Clarke and digits  Accepts: 16  Submissions: 29  Time Limit: 5000/3000 MS (Java/Others)  Memory Limi ...

  5. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  6. hdu 5565 Clarke and baton 二分

    Clarke and baton Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  7. 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 ...

  8. hdu 5465 Clarke and puzzle 二维线段树

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  9. hdu 5464 Clarke and problem dp

    Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...

随机推荐

  1. C#.NET动态页面静态化生成

    一,动态页面生成静态也的思路是怎样呢? 1>首先我们都是需要有一个静态模板,这模板的作用就是静态页的最基本模板,如下代码: <!DOCTYPE HTML PUBLIC "-//W ...

  2. MVC与设计模式的关系及MVC的实现原理和设计原理

    1 MVC介绍 众所周知MVC不是设计模式,是一个比设计模式更大一点的模式,称作设计模式不合理,应该说MVC它是一种软件开发架构模式,它包含了很多的设计模式,最为密切是以下三种:Observer (观 ...

  3. C#面试 笔试题 三

    1.传入某个属性的set方法的隐含参数的名称是什么? value,它的类型和属性所声名的类型相同.   2.C#支持多重继承么? 类之间不支持,接口之间支持.类对接口叫做实现,不叫继承. 3.C#中所 ...

  4. Css中的!important

    转载自:https://www.cnblogs.com/cang12138/p/7326280.html !important为开发者提供了一个增加样式权重的方法,比直接在元素的 style 属性中设 ...

  5. 4.ireport基本使用

    转自:https://wenku.baidu.com/view/104156f9770bf78a65295462.html 第一部分,下载与安装 Ireport官网:http:// jasperfor ...

  6. 2018-2-13-Win10-UWP-Intro-to-controls-and-events

    title author date CreateTime categories Win10 UWP Intro to controls and events lindexi 2018-2-13 17: ...

  7. Python中字符串的格式化

    字符串的格式化 格式化是对字符串进行格式表示的方式.使用槽({})按顺序格式化字符串. 格式化方式 <模板字符串>.format(<逗号分割参数>) "{ }:计算机 ...

  8. 初学Java 数值运算符

    import java.util.Scanner; public class DisplayTime { public static void main(String[] args) { Scanne ...

  9. JDBC简单总结

    几种常用数据库的JDBC URL 对于 Oracle 数据库连接,采用如下形式: jdbc:oracle:thin:@localhost:1521:sid 对于 SQLServer 数据库连接,采用如 ...

  10. day16 python模块 正则表达式

    day16 python   一.模块     1.什么是模块         是一组功能的集合     2.模块的类型         内置模块; python提供的, 解释器自带的         ...