其实是一道状态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. 5CSS之字体font-family

    ---------------------------------------------------------------------------------------------------- ...

  2. js的toFixed解惑

    js中的toFixed,C#中的Math.round都是按照银行家算法的定义来算的,这里只拿js作参考,各个浏览器的计算方式并不一样,先看一张图,对比参数很容易就发现了其中的不同之处: 前三个Chro ...

  3. Product Device Lot

    Product是指产品: 这个Product可以在不同的设备类型上生产, 同一类型的设备也可能硬件有差异,所以会有相对应的Device(Recipe): 同一Product(或同一Device)由于数 ...

  4. JS监听事件错误:Uncaught TypeError: xx(函数名)is not a function at HTMLInputElement.onclick

    事件监听一直出错,提示已定义的函数名不是一个函数,折腾了好久才想到,原来是函数名和JS内部关键字重名造成的. 以前也遇到过这种情况,但因为发生的概率比较小,就没太在意,但是这次感觉这方面确实需要注意, ...

  5. TCP:三次握手,URG、ACK、PSH、RST、SYN、FIN 含义

    http://blog.csdn.net/wudiyi815/article/details/8505726 TCP:SYN ACK FIN RST PSH URG简析   三次握手Three-way ...

  6. js的一些老司机写法

    //取整 parseInt(a,10); //Before Math.floor(a); //Before a>>0; //Before ~~a; //After a|0; //After ...

  7. Unittest加载执行用例的方法总结

    前言 说到测试框架,unittest是我最先接触的自动化测试框架之一了, 而且也是用的时间最长的, unittest框架有很多方法加载用例,让我们针对不同的项目,不同项目的大小及用例的多少自己选择加载 ...

  8. ES6学习历程(变量的声明)

    2019-01-25: 一:变量的声明: 1.对于变量的声明添加了let,const两种方式 关于let: (1)不存在变量提升--必须先声明再使用; (2)会出现暂时性死区--在一个方法外用var声 ...

  9. 洛谷——P3205 [HNOI2010]合唱队

    P3205 [HNOI2010]合唱队 题目描述 为了在即将到来的晚会上有更好的演出效果,作为AAA合唱队负责人的小A需要将合唱队的人根据他们的身高排出一个队形.假定合唱队一共N个人,第i个人的身高为 ...

  10. [luogu4728 HNOI2009] 双递增序列 (dp)

    传送门 Solution 前几天刚做了类似题,这种将一个序列拆分为两个单调序列的题一般都是设\(dp[i]\)表示i为一个单调序列的末尾时,另一个序列的末尾是多少 然后应用贪心的思想,在这道题中就是让 ...