Problem Description soda has a set S with n integers {1,2,…,n}. A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of S are key set.   Input There are multiple test cases. The first…
The Goddess Of The Moon Sample Input 2 10 50 12 1213 1212 1313231 12312413 12312 4123 1231 3 131 5 50 121 123 213 132 321   Sample Output 86814837 797922656 题意:给你n个字符串,若是一个的后缀与一个的前缀相同的大于1,则表示这两个可以连接到一起,问M个字符串相连的方案数 若a  b可以合并,可以让他们相连,然后求在一个图中走m-1步的方案数…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6470 题意:求,直接矩阵快速幂得f(n)即可 构造矩阵如下: n^3是肯定得变换的,用二项式展开来一点点配吧 我们会发现中间6*6的矩阵是个常数矩阵,则可以化为A=B^(N-2)*C(n-2次幂是因为我们求解是从N=3开始的),根据矩阵快速幂算出B^(N-2)次幂即可以了 矩阵快速幂的时间复杂度是logn 注意:我们中间构造的矩阵必须是一个方阵,矩阵快速幂的难点就在于构建中间的方阵 比如矩阵A,B,…
Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 108    Accepted Submission(s): 36 Special Judge Problem Description Once there was a special graph. This graph had n vertices a…
Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your job is simple, for each task, you should output Fn module 109+7.   Input The first line has only one integer T, indicates the number of tasks. Then,…
题目链接 我们可以把棱柱拆成有\(n\)条高的矩形,尝试递推. 在计算的过程中,第\(i\)列(\(i\neq n\))只与\(i-1\)列有关,称\(i-1\)列的上面/下面为左上/左下,第\(i\)列的上面/下面为右上/右下. 我们可以发现,右上可选的颜色数与左上和右下是否同色有关,右下同理,那就记\(f[i][0/1][0/1]\)表示左上与右下是否同色,左下与右上是否同色. 但是第\(n\)列和第\(1\)列不能同色,最后怎么算答案? 不知道第\(n\)列状态算不了,所以我们还要记第\(…
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e9+7. Input There is one integer T in the first line. The next T lines,each line includes two integers N and M . 1<=T<=10000,1<=N,M<2^63. Output…
Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1731    Accepted Submission(s): 656 Problem Description Let us define a sequence as below F1=A F2=B Fn=C⋅Fn−2+D⋅Fn−1+⌊Pn⌋ Your job is s…
目录 题目链接 思路 代码 题目链接 传送门 思路 十进制矩阵快速幂. 代码 #include <set> #include <map> #include <deque> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <bitset> #include <cstdio> #include &l…
题目链接 题意 : 有种不同的字符,每种字符有无限个,要求用这k种字符构造两个长度为n的字符串a和b,使得a串和b串的最长公共部分长度恰为m,问方案数 分析 : 直觉是DP 不过当时看到 n 很大.但是 m 很小的时候 发现此题DP并不合适.于是想可能是某种组合数学的问题可以直接公式算 看到题解的我.恍然大悟.对于这种数据.可以考虑一下矩阵快速幂优化的DP 首先要想到线性递推的 DP 式子 最直观的想法就是 dp[i][j] = 到第 i 个位置为止.前面最长匹配长度为 j 的方案数 但是如果仔…