HDU 5434
其实是一道状态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的更多相关文章
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- JavaScript中对象转换为原始值的规则
JavaScript中对象转换为原始值遵循哪些原则? P52 对象到布尔值对象到布尔值的转换非常简单:所有的对象(包括数字和函数)都转换为true.对于包装对象亦是如此:new Boolean(fal ...
- 【转】深入理解Java多态原理
之前一直知道多态是什么东西,平时敲代码也经常用到多态,但一直没有真正了解多态底层的运行机制到底是怎么样的,这两天才研究明白点,特地写下来,跟各位同学一起进步,同时也希望各位大神指导和指正. 多态的概念 ...
- [转]mysql视图学习总结
转自:http://www.cnblogs.com/wangtao_20/archive/2011/02/24/1964276.html 一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个 ...
- Elasticsearch的索引模块(正排索引、倒排索引、索引分析模块Analyzer、索引和搜索、停用词、中文分词器)
正向索引的结构如下: “文档1”的ID > 单词1:出现次数,出现位置列表:单词2:出现次数,出现位置列表:…………. “文档2”的ID > 此文档出现的关键词列表. 一般是通过key,去 ...
- PD(Power Delivery)充电协议
关于PD的历史进程,可以在我转载的另一篇文章中了解 http://www.cnblogs.com/Hello-words/p/7851627.html PD 1.0 用的是 BFSK在 VBUS上进行 ...
- centos7下手动制作trove镜像
获取镜像 [root@bldattet1 ~]# wget http://mirrors.aliyun.com/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64 ...
- Angular——引入模板指令
基本介绍 引入模板一般都是固定的东西,比如导航栏,比如页面的底部,每个页面都重复写很麻烦,不如直接定义两个模板,引入到需要的页面中.这个过程实际是一个跨域的异步请求过程. 基本使用 <!DOCT ...
- [HNOI2004]宠物收养所 题解
一杯茶,一包烟,一道水题调一天 题面 这题一眼看上去就是个裸板子对吧 本来以为要两棵splay,读了一下题发现店里只能有一种生物(人/宠物) 所以记录一下当前店里的状态就行了 老年手速20min过编译 ...
- 在centos安装 sql server
主要参考官方文档https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-red-hat
- select2下拉插件
下拉单选: 1.行内 1)初始化数据: <select class="form-control select5"> <option selected>张三1 ...