[HDU2294] Pendant - 矩阵加速递推
Pendant
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1032 Accepted Submission(s): 535
Saint Valentine's Day, Alex imagined to present a special pendant to
his girl friend made by K kind of pearls. The pendant is actually a
string of pearls, and its length is defined as the number of pearls in
it. As is known to all, Alex is very rich, and he has N pearls of each
kind. Pendant can be told apart according to permutation of its pearls.
Now he wants to know how many kind of pendant can he made, with length
between 1 and N. Of course, to show his wealth, every kind of pendant
must be made of K pearls.
Output the answer taken modulo 1234567891.
input consists of multiple test cases. The first line contains an
integer T indicating the number of test cases. Each case is on one line,
consisting of two integers N and K, separated by one space.
Technical Specification
1 ≤ T ≤ 10
1 ≤ N ≤ 1,000,000,000
1 ≤ K ≤ 30
2 1
3 2
8
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define ll long long
#define mod 1234567891
#define N 32
int T;
ll n, k; struct Mat
{
ll a[N][N];
Mat() {memset(a, , sizeof a);}
inline void clear() {memset(a, , sizeof a);}
inline void ini() {for(int i=;i<=k;i++)a[i][i]=;}
friend Mat operator * (Mat x, Mat y)
{
Mat z;
for (register int p = ; p <= k ; p ++)
{
for (register int i = ; i <= k ; i ++)
{
for (register int j = ; j <= k ; j ++)
{
z.a[i][j] = (z.a[i][j] + x.a[i][p] * y.a[p][j]) % mod;
}
}
}
return z;
}
friend Mat operator ^ (Mat x, ll y)
{
Mat z;z.ini();
while (y)
{
if (y & ) z = z * x;
x = x * x;
y >>= ;
}
return z;
}
}G, B, C;
inline void init() {G.clear(), B.clear(), C.clear();} int main()
{
scanf("%d", &T);
while (T--)
{
init();
scanf("%lld%lld", &n, &k);
G.a[][] = , G.a[][k] = ;
G.a[][] = ;
for (register int i = ; i <= k ; i ++)
{
G.a[i][i] = i;
G.a[i][i-] = k - i + ;
}
// for (int i=0;i<=k;i++,puts(""))for(int j=0;j<=k;j++) printf("%d ",G.a[i][j]) ;
B.a[][] = k;
C = G ^ n;
C = C * B;
cout<<C.a[][]<<endl;
}
return ;
}
[HDU2294] Pendant - 矩阵加速递推的更多相关文章
- luogu题解 P1707 【刷题比赛】矩阵加速递推
题目链接: https://www.luogu.org/problemnew/show/P1707 分析: 洛谷的一道原创题,对于练习矩阵加速递推非常不错. 首先我们看一下递推式: \(a[k+2]= ...
- bzoj2004公交线路——DP+矩阵加速递推
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2004 求方案数,想到DP: 因为两个站间距离<=p,所以每p个站中所有车一定都会停靠至 ...
- 矩阵经典题目七:Warcraft III 守望者的烦恼(矩阵加速递推)
https://www.vijos.org/p/1067 非常easy推出递推式f[n] = f[n-1]+f[n-2]+......+f[n-k]. 构造矩阵的方法:构造一个k*k的矩阵.当中右上角 ...
- [模板][题解][Luogu1939]矩阵乘法加速递推(详解)
题目传送门 题目大意:计算数列a的第n项,其中: \[a[1] = a[2] = a[3] = 1\] \[a[i] = a[i-3] + a[i - 1]\] \[(n ≤ 2 \times 10^ ...
- 【csp模拟赛3】bridge.cpp--矩阵加速递推
题目描述 穿越了森林,前方有一座独木桥,连接着过往和未来(连接着上一题和下一题...). 这座桥无限长. 小 Q 在独木桥上彷徨了.他知道,他只剩下了 N 秒的时间,每一秒的时间里,他会向 左或向右移 ...
- HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...
- CH 3401 - 石头游戏 - [矩阵快速幂加速递推]
题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ ...
- POJ3070 Fibonacci(矩阵快速幂加速递推)【模板题】
题目链接:传送门 题目大意: 求斐波那契数列第n项F(n). (F(0) = 0, F(1) = 1, 0 ≤ n ≤ 109) 思路: 用矩阵乘法加速递推. 算法竞赛进阶指南的模板: #includ ...
- HDU 1757 矩阵快速幂加速递推
题意: 已知: 当x<10时:f(x)=x 否则:f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + --+ a9 * f(x-10); 求:f(x ...
随机推荐
- 【学习笔记】第一章 python安全开发简介
1.1为什么黑客喜欢用python? python为我们提供了非常完善的基础代码库,覆盖了网络.文件.GUI.数据库.文本等大量内容,被形象的称为“”内置电池“”,用python开发,许多功能不必从零 ...
- Aspose.Cell导出带chart图表
最终实现的效果就是这样,代码比较多,我放在了CSDN上了,是无需模板的,别听网上瞎吹,说什么要模板,地址是:https://download.csdn.net/download/chanelwtt/1 ...
- Docker学习之Dockerfile
通过编写简单的文件创建docker镜像 dockerfile 用来创建docker镜像. 格式 : FROM alpine:latest MAINTAINER XSW CMD echo "h ...
- 【PyTorch】Tricks 集锦
声明:本文大部分内容是从知乎.博客等知识分享站点摘录而来,以方便查阅学习.具体摘录地址已在文章底部引用部分给出. 1. 查看模型每层输出详情 from torchsummary import summ ...
- [Leetcode][动态规划] 第935题 骑士拨号器
一.题目描述 国际象棋中的骑士可以按下图所示进行移动: 我们将 “骑士” 放在电话拨号盘的任意数字键(如上图所示)上,接下来,骑士将会跳 N-1 步 ...
- 第六届蓝桥杯java b组第三题
第三题 三羊献瑞 观察下面的加法算式: 其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字. 请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容. 答案这个题目完全可以使用暴 ...
- Centos7 快速安装Docker
写在前面 Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.开发者在笔记本上编译测试通过的容器可以轻松批量地在生产环境中部署. 网上的安装教程也很多这里我推 ...
- vue-router路由元信息及keep-alive组件级缓存
路由元信息?(黑人问号脸???)是不是这么官方的解释很多人都会一脸懵?那么我们说meta,是不是很多人恍然大悟,因为在项目中用到或者看到过呢? 是的,路由元信息就是我们定义路由时配置的meta字段:那 ...
- Spring MVC-从零开始-@RequestMapping 注解method属性
1.@RequestMapping 处理 HTTP 的各种方法(GET, PUT, POST, DELETE PATCH) package com.jt; import org.springfram ...
- 配置Redis(远程访问及授权设置)
配置Redis(远程访问及授权设置) 1.将redis.conf里面的bind 127.0.0.1这一行注释掉,添加自己服务器的IP 2. 还有,找到protected-mode这行, 将改为yes. ...