其实是一道状态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. 微信小程序连接Java后台

    有人问我小程序怎么连后台,这里直接贴代码 在app.js里 // api request request(url, params) { return new Promise((resolve, rej ...

  2. mysql在linux下的安装(5.7版本以后)

    1.添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组. ①groupadd mysql ②useradd -r -g mysql mysql 2.将二进制文件解压到指定的 ...

  3. Android 显示意图和隐式意图的区别

    意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么.        意图的作用:        1.激活组件   ...

  4. 【Spring】AOP

    AOP 编程允许你把遍布应用各处的功能分离出来形成可重用的组件,将安全.事务和日志关注点与你的核心业务逻辑相分离. 面向切面编程往往被定义为促使应用程序分离关注点的一项技术.系统由许多不同组件组成,每 ...

  5. Android项目实战_手机安全卫士进程管理

    ###1.设备进程信息获取获取设备运行进程 ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVI ...

  6. Android基础TOP4_1:点击物理按钮弹出退出提示框

    JAVA: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedIns ...

  7. python调用java API

    JPype documentation JPype is an effort to allow python programs full access to java class libraries. ...

  8. php字符串无乱码截取函数封装

    /** * * 中英混合字符串长度判断 * @param unknown_type $str * @param unknown_type $charset */ function strLength( ...

  9. 发布自己的nuget包

    1.先到www.nuget.org注册账户,然后在用户中心获取apikey 2.到https://dist.nuget.org/index.html下载最新的nuget.exe,放到你的项目根目录下 ...

  10. vue04 组件化开发 Vue自动化工具

    5. 组件化开发 5.1 组件[component] 组件(Component)是自定义封装的功能.在前端开发过程中,经常出现多个网页的功能是重复的,而且很多不同的网站之间,也存在同样的功能. 而在网 ...