2019.2.26考试T2 矩阵快速幂加速DP】的更多相关文章

\(\color{#0066ff}{题解 }\) 可以发现, 数据范围中的n特别小,容易想到状压 可以想到类似于状压DP的思路,按列进行转移 那么应该有3维,\(f[i][j][k]\)代表到第i列,j的每一位表示这一行有多少连续的男生,k表示当前有多少列全是男生,的方案数 看到m的范围,我们肯定是要找一个\(O(logm)\)的东西加速转移,自然是矩阵加速 然后我们来看看有多少个状态,看看是否可行 j有\(p^n\)个,k有q个(用矩阵转移第一维自然不需要) 那么状态数依然达到了一个\(p^n…
Description 阿 申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0<=Xi<=9),他不希望准考证号上出现不吉利的数字.他的不吉利数学 A1A2...Am(0<=Ai<=9)有M位,不出现是指X1X2...Xn中没有恰好一段等于A1A2...Am. A1和X1可以为0 Input 第一行输入N,M,K.接下来一行输入M位的数. 100%数据N<=10^9,M<=20,K<=1000 40%数据N<=1000 10%数据N<=6…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1009 字符串计数DP问题啊...连题解都看了好多好久才明白,别提自己想出来的蒟蒻我... 首先要设计一个不太好想的状态:f[i][j]表示大串上到第 i 位时有小串前 j 位的后缀,且不包含整个小串的方案数: 也就是如果小串是 12312 , f[5][3] 表示目前大串的情况是 **123... : 这个状态要从 i 转移到 i+1 ,还需要一个帮助它的数组 a,a[i][j]表示在长度…
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1009 这道题一看数据范围:$ n<=10^9 $,显然不是数学题就是矩乘快速幂优化dp. 我们设$ f[i][j] $表示前$ i $位匹配不吉利数字$ j $位时的方案数,因为每一位的转移方式都是相同的,于是用kmp预处理出转移矩阵,直接矩乘快速幂就能过了. #include<cstdio> #include<cmath> #include<cstdlib…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn, the cows would stand in a line, while John writes two positive numbers…
题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ 这 $10$ 个数字指明.操作序列是一个长度不超过 $6$ 且循环执行.每秒执行一个字符的字符串.每秒钟,所有格子同时执行各自操作序列里的下一个字符.序列中的每个字符是以下格式之一:数字 $0 \sim 9$:表示拿 $0 \sim 9$ 个石头到该格子.$NWSE$:表示把这个格子内所有的石头推…
传送门 矩阵快速幂优化dp简单题. 考虑状态转移方程: f[time][u]=∑f[time−1][v]f[time][u]=\sum f[time-1][v]f[time][u]=∑f[time−1][v] 把一个点拆成9个来转换边长,然后根据题意模拟连边就行了. 最后用矩阵快速幂优化一下转移就能过啦. 代码: #include<bits/stdc++.h> using namespace std; int n,t,m; char s[50]; const int mod=2009; str…
CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 558    Accepted Submission(s): 227 Problem Description CRB is now playing Jigsaw Puzzle.There are N kinds of pieces with infinite s…
E. Okabe and El Psy Kongroo     Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points…
题意: 已知: 当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)%m的值. 思路: 矩阵快速幂加速递推. 嗯嗯 // by SiriusRen #include <cstdio> #include <cstring> using namespace std; int cases,k,ans,a[10][10],mod; struct matrix…