Tri Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7841   Accepted: 4113 Description In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle.  Input Input consists of several t…
poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.net/JudgeOnline/problem.php?pid=148 思路: 矩阵快速幂 直接求取 代码: #include <iostream> #include <string.h> #include <math.h> #include <stdio.h>…
题目 还是一道基础的矩阵快速幂. 具体的居者的幂公式我就不明示了. #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ; struct matrix { ][]; }; matrix multiply(matrix x,matrix y)//矩阵乘法 { matrix temp; ;i<num;i++) { ;j<num;j++) { ; ;k<n…
题目链接 题意 : 用矩阵相乘求斐波那契数的后四位. 思路 :基本上纯矩阵快速幂. #include <iostream> #include <cstring> #include <cstdio> using namespace std; struct Matrix { ][]; }; int n; Matrix matrix_mul(Matrix a,Matrix b) { Matrix c; ; i < ; i++) { ; j < ; j++) { c…
题目链接:https://vjudge.net/problem/POJ-2778 题意:输入n和m表示n个病毒,和一个长为m的字符串,里面只可以有'A','C','G','T' 这四个字符,现在问这个长为m的字符串里面不可以出现任何病毒的情况有多少. 参考的两篇博客: http://www.cnblogs.com/LQLlulu/p/9344774.html https://blog.csdn.net/morgan_xww/article/details/7834801 上面的博客写得很好,可以…
题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * dp[i]; 然而...t,但这个式子明显可以用矩阵快速幂加个氮气一下加速一下... 把所有的点输入之后 sort一下,那么就能把这条路分成很多段 每一段以地雷为分界线 1 - x[0]  x[0]+1 - x[1]  x[1]+1 - x[2] ````````` 然后求出安全通过每一段的概率  …
<题目链接> Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … An alternative formula for the Fibonacci seq…
题目链接 Description Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, gree…
题意:个n个方块涂色, 只能涂红黄蓝绿四种颜色,求最终红色和绿色都为偶数的方案数. 该题我们可以想到一个递推式 .   设a[i]表示到第i个方块为止红绿是偶数的方案数, b[i]为红绿恰有一个是偶数的方案数, c[i]表示红绿都是奇数的方案数. 那么有如下递推可能: 递推a[i+1]:1.到第i个为止都是偶数,且第i+1个染成蓝或黄:2.到第i个为止红绿恰有一个是奇数,并且第i+1个方块染成了奇数对应的颜色. 递推b[i+1]:1.到第i个为止都是偶数,且第i+1个染成红或绿:2.到第i个为止…
题目:传送门 题意: 给你m个病毒串,只由(A.G.T.C) 组成, 问你生成一个长度为 n 的 只由 A.C.T.G 构成的,不包含病毒串的序列的方案数. 解: 对 m 个病毒串,建 AC 自动机, 然后, 这个AC自动机就类似于一张有向图, 可以用邻接矩阵存这张有向图. 最多10个病毒串, 每个病毒串长度不超过 10, 那最多是个 100 * 100 的矩阵, 可以接受. 最后用矩阵快速幂加速推导. #include<cstdio> #include<cstring> #inc…