题目传送门 题目描述:给出n,x,mod.求s[n]. s[n]=s[n-1]+(x^n)*(n^x)%mod; 思路:这道题是hdu5950的进阶版.大家可以看这篇博客hdu5950题解. 由于n很大,所以肯定是矩阵快速幂的题目,但是矩阵快速幂只能解决线性的问题,n^4在这个式子中是非线性的,后一项和前一项没有什么直接关系,这里要做一个转换,把n^4变成一个线性的,也就是和(n-1)^4有关系的东西,而这个办法就是: n^4=(n-1+1)^4=(n-1)^4+4*(n-1)^3+6*(n-1…
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. 在计算机科学中,二叉树是每个结点最多有两个子结点的有序树.通常子结点被称作“左孩子”和“右孩子”.二叉树被用作二叉搜索树和二叉堆.随后他又和他人讨论起了二叉搜索树.什么是二叉搜索树呢?二叉搜索树首先是一棵二叉树.设key[p]表示结点p上的数值.对于其中的每个结点p,若其存在左孩子lch,则key…
题目分析: 用数论分块的思想,就会发现其实就是连续一段的长度$i$的高度不能超过$\lfloor \frac{k}{i} \rfloor$,然后我们会发现最长的非$0$一段不会超过$k$,所以我们可以弄一个长度为$i$的非$0$段的个数称为"元",然后用"元"去递推. 这个"元"的求法用DP:令数论分块之后第$i$段的长度为$g[i]$ $$f[i][j] = f[i-1][j] + f[i-1][k]*f[i][j-k-1]*g[i]$$ $$…
题目链接:https://vjudge.net/problem/HDU-4565 So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5525    Accepted Submission(s): 1841 Problem Description A sequence Sn is defined as:Where a, b,…
Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N-1 dimension. How many pieces will the “ball” be cut into most?However, it’s impossible to understand the following statement without any explanation.L…
题目链接:https://vjudge.net/problem/UVA-10655 题意: a+b.ab的值分别为p.q,求a^n+b^n. 题解: 1.a.b未知,且直接求出a.b也不太实际. 2.看到 a^n+b^n 这个式子就想到二阶齐次递推式的通项公式,然后就想是否能通过通项公式反推回递推式.结果发现a.b的值是不能确定是否相等的,而求二阶齐次递推式的通项公式时,是需要根据根的情况来分类求解的,所以此题不适应. 3.那么,就直接对 a^n+b^n 做一下变形: 4.得到递推式之后,就直接…
Description Queues and Priority Queues are data structures which are known to most computer scientists. The Queue occurs often in our daily life. There are many people lined up at the lunch time. Now we define that ‘f’ is short for female and ‘m’ is…
题目链接: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…
Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10);  And ai(0<=i<=9) can only be 0 or 1 .  Now, I will give a0 ~ a9 and two positive integers k…
Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3078    Accepted Submission(s): 1117 Problem Description Bob's school has a big playground, boys and girls always play games here after s…
题目链接:传送门 题目: 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…
题目:uva10401Injured Queen Problem(递推) 题目大意:依然是在棋盘上放皇后的问题,这些皇后是受伤的皇后,攻击范围缩小了.攻击范围在图中用阴影表示(题目).然后给出棋盘的现状,???3?4:在一个6*6的棋盘上,由于皇后是能够列向攻击的,所以一列仅仅能放一个皇后,所以第一个?代表第一列的皇后放的行未知,这样3的意思就是第4列皇后在第三行.也就是确定了第4列皇后的位置. 要求棋盘上的皇后不互相攻击.问这种棋盘能够有多少不同的放法. 解题思路:一開始想状态.想把不同的棋盘…
题目传送门 题目描述:给出一个数列的第一项和第二项,计算第n项. 递推式是 f(n)=f(n-1)+2*f(n-2)+n^4. 由于n很大,所以肯定是矩阵快速幂的题目,但是矩阵快速幂只能解决线性的问题,n^4在这个式子中是非线性的,后一项和前一项没有什么直接关系,所以模拟赛的时候想破头也不会做. 这里要做一个转换,把n^4变成一个线性的,也就是和(n-1)^4有关系的东西,而这个办法就是: n^4=(n-1+1)^4=(n-1)^4+4*(n-1)^3+6*(n-1)^2+4*(n-1)^1+(…
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 155 Accepted Submission(s): 110   Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If…
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…
题目链接:http://47.93.249.116/problem.php?id=2182 题目描述 河神喜欢吃零食,有三种最喜欢的零食,鱼干,猪肉脯,巧克力.他每小时会选择一种吃一包. 不幸的是,医生告诉他,他吃这些零食的时候,如果在连续的三小时内他三种都吃了,并且在中间一小时 吃的是巧克力,他就会食物中毒.并且,如果河神在连续三小时内吃到相同种类的食物,他就会不开心. 假设每种类零食的数量都是无限的,那么如果经过n小时,让河神满意的零食吃法有多少种呢?(开心又不 会食物中毒的吃法)答案可能过…
Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6639    Accepted Submission(s): 2913 Problem Description Queues and Priority Queues are data structures which are known to most computer…
http://www.lightoj.com/volume_showproblem.php?problem=1244 题意:给出六种积木,不能旋转,翻转,问填充2XN的格子有几种方法.\(N <= 10^9 \) 思路:首先手写出前几项,猜出递推式,如果真有比赛出这种题,又不能上网进工具站查是吧?N比较大显然用矩阵快速幂优化一下 /** @Date : 2016-12-18-22.44 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : ht…
Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1146    Accepted Submission(s): 491 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single…
Problem Description Queues and Priority Queues are data structures which are known to most computer scientists. The Queue occurs often in our daily life. There are many people lined up at the lunch time.   Now we define that ‘f’ is short for female a…
链接:  https://www.codechef.com/FEB18/problems/BROCLK Broken Clock Problem Code: BROCLK Chef has a clock, but it got broken today — the minute hand on Chef's clock doesn't rotate by the angle 2π/3600 each second, but by a different fixed angle x. The c…
http://acm.hdu.edu.cn/showproblem.php?pid=2604 Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8567    Accepted Submission(s): 3749 Problem Description Queues and Priority Queues are da…
题目: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的范围很大,我们直接递推过去肯定超时,线性递推超时,那么肯定要用矩阵快速幂,但是这个有事二维的 那么我们只能想下怎么改成是一维的递推式,我们可以…
概述 系数为常数,递推项系数均为一次的,形如下面形式的递推式,称为线性递推方程. \[f[n]=\begin{cases} C &n\in Value\\ a_1 f[n-1]+a_2 f[n-2]+⋯a_t f[n-t]&n∉Value \end{cases}\] \((a_1,a_2,-,a_t,C∈\mathbb{R},0<t<n)\) 其中\(Value\)为终止条件的集合. 例如:斐波那契\((Fibonacci)\)数列则通过下面这个线性递推方程定义 \[f[n]=…
矩阵乘法,顾名思义矩阵与矩阵相乘, 两矩阵可相乘的前提:第一个矩阵的行与第二个矩阵的列相等 相乘原则: a b     *     A B   =   a*A+b*C  a*c+b*D c d      C D   =   c*A+d*C  c*A+d*C 上代码 struct matrix { ll a[maxn][maxn]; }; matrix matrix_mul(matrix x,matrix y) { matrix temp; ;i<=n;i++) ;j<=n;j++) { tem…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个环可以取下或放上,cost=1.求最小cost.MOD 200907. 解题思路: 递推公式 题目意思非常无聊,感觉是YY的. 设$dp[i]$为取第i个环时的总cost. $dp[1]=1$,$dp[2]=2$,前两个环取下是没有条件要求的. 从i=3开始,由于条件对最后的环限制最大,所以从最后一…
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4331    Accepted Submission(s): 2603 Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) =…
本文出自:blog.csdn.net/svitter 原题:http://acm.hdu.edu.cn/showproblem.php?pid=2045 题意:中文不用我说了吧. 这个题目的关键就在于递推方程--以及错误的测试数据 首先这个题目就是简单的置换群着色问题-- 去除了反转的问题,难一点的大家可以看P197(离散数学,高等教育出版社) 我在做这个题目的时候首先被f [ 1 ]  = 3 困扰了..拜托,根本不符合题意好吗- =一个格子能说是首尾颜色不同吗? 后来写错了递推方程--f […
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 递推式是百度的,主要是练习一下如何使用矩阵快速幂优化. 递推式:f(n)=f(n-1)+f(n-3)+f(n-4),其中f(0)=2, f(1)=4, f(2)=6, f(3)=9. 当n>4时候,需要通过这个关系来递推. 构造矩阵这种东西我以前一直认为是很玄学的,但是如果深入研究的话不难发现其实也有规律可循.这是一个齐次递推式,很好构造. 我们希望通过如下矩阵(1)得到矩阵(2) | f(n…
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a_5&a_6&a_7&a_8&a_9\\ 1&0&0&0&0&0&0&0&0&0\\ 0&1&0&0&0&0&0&0&0&0\\ 0&…