题目链接: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…
题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description Farmer John likes to play mathematics games with his N cows. Recently, they are attracted…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn,…
题意: 已知: 当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…
题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ 这 $10$ 个数字指明.操作序列是一个长度不超过 $6$ 且循环执行.每秒执行一个字符的字符串.每秒钟,所有格子同时执行各自操作序列里的下一个字符.序列中的每个字符是以下格式之一:数字 $0 \sim 9$:表示拿 $0 \sim 9$ 个石头到该格子.$NWSE$:表示把这个格子内所有的石头推…
题意:递推公式 Fn = Fn-1 + 2 * Fn-2 + n*n,让求 Fn; 析:很明显的矩阵快速幂,因为这个很像Fibonacci数列,所以我们考虑是矩阵,然后我们进行推公式,因为这样我们是无法进行运算的.好像有的思路,最后也没想出来,还是参考的大牛的博客 http://blog.csdn.net/spring371327/article/details/52973534 那是讲的很详细了,就不多说了,注意这个取模不是1e9+7,一开始忘了.. 代码如下: #pragma comment…
题目链接:传送门 题目: 题目描述 小L有一座环形花园,沿花园的顺时针方向,他把各个花圃编号为1~N(<=N<=^).他的环形花园每天都会换一个新花样,但他的花园都不外乎一个规则,任意相邻M(<=M<=,M<=N)个花圃中有不超过K(<=K<M)个C形的花圃,其余花圃均为P形的花圃. 例如,N=,M=,K=.则 CCPCPPPPCC 是一种不符合规则的花圃: CCPPPPCPCP 是一种符合规则的花圃. 请帮小L求出符合规则的花园种数Mod 由于请您编写一个程序解…
Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 Input 输入两个整数M,N.1<=M<=10^8,1<=N<=10^12 Output 可能越狱的状态数,模100003取余 Sample Input 2 3 Sample Output 6 HINT 6种状态为(000)(001)(011)(100)(110)(111) 分析 注意一…
题目链接:传送门 题目: 石头游戏 0x30「数学知识」例题 描述 石头游戏在一个 n 行 m 列 (≤n,m≤) 的网格上进行,每个格子对应一种操作序列,操作序列至多有10种,分别用0~9这10个数字指明. 操作序列是一个长度不超过6且循环执行.每秒执行一个字符的字符串.每秒钟,所有格子同时执行各自操作序列里的下一个字符.序列中的每个字符是以下格式之一: 数字0~:表示拿0~9个石头到该格子. NWSE:表示把这个格子内所有的石头推到相邻的格子,N表示上方,W表示左方,S表示下方,E表示右方.…
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…
题目链接:传送门 题目大意: 求斐波那契数列第n项F(n). (F(0) = 0, F(1) = 1, 0 ≤ n ≤ 109) 思路: 用矩阵乘法加速递推. 算法竞赛进阶指南的模板: #include <iostream> #include <cstring> using namespace std; ; ], ][]) { ]; memset(c, , sizeof c); ; j < ; j++) { ; k < ; k++) { c[j] = (c[j] + 1…
\(\color{#0066ff}{题解}\) 然后a,b,c通过矩阵加速即可 为什么1出现偶数次3没出现的贡献是上面画绿线的部分呢? 考虑暴力统计这部分贡献,答案为\(\begin{aligned}\sum_{2|i}C_n^i*3^{n-i}\end{aligned}\) 显然如果没有\(\sum\)下面的限制,它就是一个生成函数\((x+3)^n\) 相当于我们只取偶数项 可以用单位根反演 把\(\omega_2^1,\omega_2^2\)分别代入\((x+3)^n\) 得到的就是2倍的…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5954 Problem DescriptionYou have got a cylindrical cup. Its bottom diameter is 2 units and its height is 2 units as well.The height of liquid level in the cup is d (0 ≤ d ≤ 2). When you incline the cup t…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 249    Accepted Submission(s): 140 Problem Description Farmer John likes to play mathematics games with his N cows. Recently, t…
题目链接:https://vjudge.net/problem/HDU-5950 Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2727    Accepted Submission(s): 1226 Problem Description Farmer John likes to play mat…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3832    Accepted Submission(s): 1662 Problem Description Farmer John likes to play mathematics games with his N cows. Recently…
Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 539    Accepted Submission(s): 204 Problem Description A clique is a complete graph, in which there is an edge between every pair…
Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 63    Accepted Submission(s): 60 Problem Description ACM ICPC is launching a thick burger. The thickness (or the height) of a piec…
Relative atomic mass Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 66    Accepted Submission(s): 59 Problem Description Relative atomic mass is a dimensionless physical quantity, the ratio of…
HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test…
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n).   Input The input consists of multiple test cases. Each test case…
A number sequence is defined as follows:  f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.  Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test cases. Each test case contains 3 integers…
题目 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 a and b on a blackboard. And then, the cows woul…
题意 设 $$f_i = \left\{\begin{matrix}1 , \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  i < k\\ \prod_{j=1}^k f_{i-j}^{b_j} \ mod \ p, \ \ \ \ \ i > k\end{matrix}\right.$$ 求 $f_k$($1 \leq f_k < p$),使得 $f_m = n$.($1 \leq k\leq 100$) 分析 $f_n$ 可以表示…
题目链接:http://hihocoder.com/problemset/problem/1143 这个递推还是很经典的,结果是斐波那契数列.f(i) = f(i-1) + f(i-2).数据范围太大了,应该用快速幂加速下. /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┃┃┃┃┃┃ ┻┻┻┻┻┻ */ #incl…
BZOJ4547 Hdu5171 小奇的集合 Description 有一个大小为n的可重集S,小奇每次操作可以加入一个数a+b(a,b均属于S),求k次操作后它可获得的S的和的最大值.(数据保证这个值为非负数) Input 第一行有两个整数n,k表示初始元素数量和操作数,第二行包含n个整数表示初始时可重集的元素. 对于100%的数据,有 n<=105,k<=109,|ai|<=10^5 Output 输出一个整数,表示和的最大值.答案对10000007取模. Sample Input…
题目:https://www.acwing.com/problem/content/228/ 题意:有一个二维矩阵,这里只给你第一行和第一列,要你求出f[n][m],关系式有    1,  f[0][m]=f[0][m-1]*10+3       2,   f[n][m]=f[n-1][m]+f[n][m-1] 思路:我们可以看出这里n的范围很小  ,m的范围很大,我们直接递推过去肯定超时,线性递推超时,那么肯定要用矩阵快速幂,但是这个有事二维的 那么我们只能想下怎么改成是一维的递推式,我们可以…
http://acm.hdu.edu.cn/showproblem.php?pid=5955 题意:给你长度为l的n组数,每个数1-6,每次扔色子,问你每个串第一次被匹配的概率是多少 题解:先建成ac自动机构造fail数组,然后因为fail指针可能向前转移所以不能不能直接递推dp,需要高斯消元解方程,对于节点i,假设不是结束点而且能转移到它的点有a1,a2...an,那么dp[i]=1/6*dp[a1]+1/6*dp[a2]+...+1/6*a[n],然后我们可以列出n个方程,高斯消元然后找到每…
记dp[i]为长度i且符合题意的方案数,dp[n]就是解 符合方案的是不含fmf和fff子串的字符串 考虑如何从前面几项递推出后面第i项 (★表示存在生成的非法方案)←其实没啥用处 i=1时 m③ f③ i=2时 mm② mf② fm★② ff★② i=3时 mmm mmf mfm★ mff★ fmm ffm★ i=4时 mmmm① mmmf① mmfm★① mmff★① mfmm① mffm★① fmmm① fmmf① ffmm① i=5时 mmmmm① mmmmf② mmmfm① mmmff…
HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. 代码总览 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <set> #…