[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 ...
随机推荐
- 2010年NOIP普及组复赛题解
题目及涉及的算法: 数字统计:入门题: 接水问题:基础模拟题: 导弹拦截:动态规划.贪心: 三国游戏:贪心.博弈论. 数字统计 题目链接:洛谷 P1179 这道题目是一道基础题. 我们只需要开一个变量 ...
- 解决在Filter中读取Request中的流后,后续controller或restful接口中无法获取流的问题
首先我们来描述一下在开发中遇到的问题,场景如下: 比如我们要拦截所有请求,获取请求中的某个参数,进行相应的逻辑处理:比如我要获取所有请求中的公共参数 token,clientVersion等等:这个时 ...
- MapReduce原理及操作
注意:本实验是对前述实验的延续,如果直接点开始实验进入则需要按先前学习的方法启动hadoop 部署节点操作系统为CentOS,防火墙和SElinux禁用,创建了一个shiyanlou用户并在系统根目录 ...
- 利用github搭建私人maven仓库
一.背景 最近在做HBase的项目,不免会引用到一些工具类,如StringUtils,NumberUtils,DateUtils这些,公司底层有封装好可以直接使用. 但是项目完成,用maven打包部署 ...
- 小程序·云开发的HTTP API调用丨实战
小程序云开发之httpApi调用. 小程序云开发之httpApi调用(返回"47001处理") 技术栈 采用 nodejs + express 搭建web服务器,采用 axios ...
- .NET Core 获取请求类容(body)
.Net Core 对于body多次读取,开放了一个参数EnableRewind(),该参数在第一次读取body之前开启,之后body信息可以多次读取:core时代取消了之前的stream.posit ...
- C# 10分钟入门基于WebOffice实现在线编辑文档,实时保存到服务器(所有office,兼容WPS)
今天,他来了(weboffice在线编辑文档). 上次写了一个在线预览的博,当然,效果并不是太理想,但是紧急解决了当时的问题. 后来,小编重新查找资料,求助大牛,终于使用新的方式替换了之前的low方法 ...
- hibernate集成ehcahe进行缓存管理
ehcace是现在非常流行的缓存框架,有轻量.灵活.可扩展.支持集群/分布式等优点. 在项目中,使用ehcace可以对数据进行缓存(一般使用.基于注解.基于aop),使用filter可以对页面进行缓存 ...
- Django+MySQL Dashboard 网页端数据库可视化
1. Overview Python+MySQL+Django, 有些数据托管在 MySQL 的数据库,然后我们希望进行可视化,通过 web 的方式对数据库的信息去进行展示/检索/维护/.. 这个项目 ...
- 用Python怎么SSH到网络设备
0. 前言 自上一篇文章<用python怎么telnet到网络设备>,简单使用了telnetlib库给大家演示了下,但是,现实环境中仍不建议去使用telnet. SSH(Secure Sh ...