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 test cases followed by a line containing -1. Each test case is a line containing an integer 0 <= n <= 30.

Output

For each test case, output one integer number giving the number of possible tilings.

Sample Input

2
8
12
-1

Sample Output

3
153
2131 思路:只有八种转移状态,设初始状态为0(全空),得到状态7(111全染)
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef vector<long long > vec;
typedef vector<vec> mat;
const int mod=(1<<31-1);
mat mul(mat &A,mat &B){
mat C(A.size(),vec(B[0].size()));
for(int i=0;i<A.size();i++){
for(int k=0;k<B.size();k++){
for(int j=0;j<B[0].size();j++){
C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
}
}
}
return C;
}
mat pow(mat A,long long n){
mat B(A.size(),vec(A.size()));
for(int i=0;i<A.size();i++){
B[i][i]=1;
}
while(n>0){
if(n&1)B=mul(B,A);
A=mul(A,A);
n>>=1;
}
return B;
}
void calc(int m){
mat m1(8,vec(8,0)),E(8,vec(8,0));
E[0][7]=1;
E[1][6]=1;
E[2][5]=1;
E[3][4]=1;
E[4][3]=1;E[4][7]=1;
E[5][2]=1;
E[6][1]=E[6][7]=1;
E[7][0]=1;E[7][4]=E[7][6]=1;
E=pow(E,m);
/*for(int i=0;i<E[0].size();i++){
for(int j=0;j<E.size();j++){
printf("%d ",E[i][j]);
}
puts("");
}*/
printf("%I64d\n",E[0][7]);
}
int main(){
int m=0;
while(scanf("%d",&m)==1&&m!=-1){
calc(m+1);
}
return 0;
}

  

POJ 2663 Tri Tiling 矩阵快速幂 难度:3的更多相关文章

  1. poj 3070 && nyoj 148 矩阵快速幂

    poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...

  2. poj 3070 Fibonacci(矩阵快速幂,简单)

    题目 还是一道基础的矩阵快速幂. 具体的居者的幂公式我就不明示了. #include<stdio.h> #include<string.h> #include<algor ...

  3. POJ 3070 Fibonacci(矩阵快速幂)

    题目链接 题意 : 用矩阵相乘求斐波那契数的后四位. 思路 :基本上纯矩阵快速幂. #include <iostream> #include <cstring> #includ ...

  4. poj 2778 AC自动机+矩阵快速幂

    题目链接:https://vjudge.net/problem/POJ-2778 题意:输入n和m表示n个病毒,和一个长为m的字符串,里面只可以有'A','C','G','T' 这四个字符,现在问这个 ...

  5. Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)

    题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...

  6. POJ 3070 Fibonacci 【矩阵快速幂】

    <题目链接> Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 ...

  7. POJ 3734 Blocks (矩阵快速幂)

    题目链接 Description Panda has received an assignment of painting a line of blocks. Since Panda is such ...

  8. POJ 3734 Blocks(矩阵快速幂+矩阵递推式)

    题意:个n个方块涂色, 只能涂红黄蓝绿四种颜色,求最终红色和绿色都为偶数的方案数. 该题我们可以想到一个递推式 .   设a[i]表示到第i个方块为止红绿是偶数的方案数, b[i]为红绿恰有一个是偶数 ...

  9. POJ 2778 DNA Sequence (矩阵快速幂 + AC自动鸡)

    题目:传送门 题意: 给你m个病毒串,只由(A.G.T.C) 组成, 问你生成一个长度为 n 的 只由 A.C.T.G 构成的,不包含病毒串的序列的方案数. 解: 对 m 个病毒串,建 AC 自动机, ...

随机推荐

  1. Linux系统编程之--守护进程的创建和详解【转】

    本文转载自:http://www.cnblogs.com/mickole/p/3188321.html 一,守护进程概述 Linux Daemon(守护进程)是运行在后台的一种特殊进程.它独立于控制终 ...

  2. Python数据分析入门之pandas基础总结

    Pandas--"大熊猫"基础 Series Series: pandas的长枪(数据表中的一列或一行,观测向量,一维数组...) Series1 = pd.Series(np.r ...

  3. ubuntu16.04下无线网卡无法正常连网

    背景:无线网卡初次连接可以正常上网,但是用了一会儿就会出现无法上网的情况 版本: Ubuntu 16.04 一.分析: 1.使用ifconfig命令发现不会显示无线网卡,说明无线网卡被关闭,笔者输出的 ...

  4. Linq in GroupBy GroupJoin

    还是上一份的代码例子: public class Person { public int ID { get; set; } public string Name { get; set; } publi ...

  5. The way to Go(1): Introduction

    Reference: Github: Go Github: The way to Go Introduction to Go 设计要求: 能够以更快的速度开发软件 开发出的软件能够很好地在现代的多核计 ...

  6. UVa 11729 突击战

    https://vjudge.net/problem/UVA-11729 题意:有n个部下,每个部下需要完成一项任务.第i个部下需要你话B分钟交代任务,然后立刻执行J分钟完成任务.安排交代任务顺序并计 ...

  7. blast 数据库说明

    Peptide Sequence Databases蛋白序列的数据库 nrAll non-redundant GenBank CDS translations + RefSeq Proteins + ...

  8. Java中的垃圾回收机制

    1. 垃圾回收的意义 在C++中,对象所占的内存在程序结束运行之前一直被占用,在明确释放之前不能分配给其它对象:而在Java中,当没有对象引用指向原先分配给某个对象的内存时,该内存便成为垃圾.JVM的 ...

  9. cartographer安装--Ubuntu14.04--indigo

    0.安装所有依赖项 sudo apt-get install -y google-mock libboost-all-dev  libeigen3-dev libgflags-dev libgoogl ...

  10. HDU2017新生赛 找方块

    思路: 先n^3预处理出每个点能到达的(1010串)最上面的行下标. 然后再n^3暴力一下,对于每个点,往左走看能走到哪,边走边更新面积. 代码: #include<bits/stdc++.h& ...