其实是一道状态DP题。都是行与行之间的转移,可以知道,当某j列中有一个象,如果存在情况i-1行j-1列有象而i,j-1位置无象则不可放,或者i-1,j+1有而i,j+1无同样不可放。

使用快速状态转移

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath> using namespace std; const int mod=1000000007;
const int MAX=(1<<7);
int TranMatrix[MAX][MAX];
int tmp[MAX][MAX];
/*
int mul(int a,int b){
int res=0;
while(b){
if(b&1) res=(res+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return res;
}
*/
int quick(int Status,int n){
int ans[MAX][MAX],for_save[MAX][MAX];
memset(ans,0,sizeof(ans));
for(int i=0;i<MAX;i++) ans[i][i]=1;
while(n){
if(n&1){
for(int i=0;i<Status;i++){
for(int j=0;j<Status;j++){
for_save[i][j]=0;
for(int k=0;k<Status;k++){
for_save[i][j]=(for_save[i][j]+1LL*ans[i][k]*tmp[k][j]%mod);
if(for_save[i][j]>mod) for_save[i][j]-=mod;
}
}
}
for(int i=0;i<Status;i++){
for(int j=0;j<Status;j++)
ans[i][j]=for_save[i][j];
}
}
n>>=1;
for(int i=0;i<Status;i++){
for(int j=0;j<Status;j++){
for_save[i][j]=0;
for(int k=0;k<Status;k++){
for_save[i][j]=(for_save[i][j]+1LL*tmp[i][k]*tmp[k][j]%mod);
if(for_save[i][j]>mod) for_save[i][j]-=mod;
}
}
}
for(int i=0;i<Status;i++){
for(int j=0;j<Status;j++)
tmp[i][j]=for_save[i][j];
}
}
int res=0;
for(int i=0;i<Status;i++)
res=(res+ans[0][i])%mod;
return res;
} int main(){
int n,m;
int Status=(1<<7);
for(int i=0;i<(Status);i++){
for(int j=0;j<Status;j++){
bool flag=true;
for(int k=0;k<7;k++){
if((((1<<k)&j)==(1<<k))&&(((1<<k)&i)==0)){
if((((1<<(k+1))&j)==0)&&(((1<<(k+1))&i)>0)){
flag=false;
break;
}
else if(k>0&&((1<<(k-1))&j)==0&&(((1<<(k-1))&i)>0)){
flag=false;
break;
}
}
}
TranMatrix[i][j]=flag?1:0;
}
}
while(scanf("%d%d",&n,&m)!=EOF){
//swap(n,m);
Status=1<<m;
for(int i=0;i<Status;i++){
for(int j=0;j<Status;j++)
tmp[i][j]=TranMatrix[i][j];
}
printf("%d\n",quick(Status,n)); }
return 0;
}

矩阵可过。

HDU 5434的更多相关文章

  1. HDU 5434 Peace small elephant 状压dp+矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant  Accepts: 38  Submissions: ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. Ubuntu中安装部署Intel CS WebRTC

    1环境要求 组件 版本要求 OS CentOS* 7.4, Ubuntu 14.04/16.04 LTS Node 8.11.* (推荐8.11.1) MongoDB 2.4.9 Boost 1.65 ...

  2. akka设计模式系列-消息模型

    通过前面的文章我们总结了几个常见的actor设计模式,但此处不得不提前介绍一下在Akka中消息的设计模式.随着对Akka的使用,我们会发现,使用Akka设计系统其实就是面向消息编程.actor之间消息 ...

  3. JavaScript--引用JS外部文件

    通过前面知识学习,我们知道使用<script>标签在HTML文件中添加JavaScript代码,如图: JavaScript代码只能写在HTML文件中吗?当然不是,我们可以把HTML文件和 ...

  4. 注解配置AOP切面编程

    1.导入先关jar包 2.编写applicationContext.xml,配置开启注解扫描和切面注解扫描 <?xml version="1.0" encoding=&quo ...

  5. Linux命令(002) -- free

    一.准备知识 Linux和Windows系统在内存管理机制方面有很大的不同.在Linux中经常发现空闲内存很少,似乎所有的内存都被系统占用了,表面感觉是内存不够用了,其实不然.这是Linux内存管理的 ...

  6. Angular——todos案例

    基本介绍 (1)视图绑定两个数组,分别对应未完成和已完成 (2)数组的删除splice(),数组的追加push() 基本使用 <!DOCTYPE html> <html lang=& ...

  7. Ajax——异步基础知识(三)

    封装异步请求 1.将函数作为参数进行使用 2.因为获取数据是在一个注册事件中获取的,所以只有事件触发的时候才会调用此函数 <!DOCTYPE html> <html lang=&qu ...

  8. 【译】x86程序员手册11- 4.1系统寄存器

    4.1 Systems Registers 系统寄存器 The registers designed for use by systems programmers fall into these cl ...

  9. Tomcat8 连接池

    1.所有的tomcat项目共用一个连接池配置 1.1 修改conf->context.xml文件,在Context节点下配置 <Resource name="jdbc/myDat ...

  10. 使用CSS3实现表格隔行/隔列变色

    <!DOCTYPE html><html><head> <meta charset="utf-8" /> <title> ...