轮廓线动态规划是一种基于状态压缩解决和连通性相关的问题的动态规划方法

这道题是轮廓线动态规划的模板

讲解可以看lrj的蓝书

代码

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long has[120][120],n,m,dp[2][1<<15],cur;//
void update(int a,int b){
if(b&(1<<m))
dp[cur][b^(1<<m)]+=dp[cur^1][a];
}
int main(){
memset(has,-1,sizeof(has));
while(scanf("%d %d",&n,&m)==2){//n>=m
if(m>n)
swap(m,n);
if(has[m][n]!=-1){
printf("%lld\n",has[m][n]);
continue;
}
cur=0;
memset(dp,0,sizeof(dp));
dp[cur][(1<<m)-1]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cur^=1;
memset(dp[cur],0,sizeof(dp[cur]));
for(int k=0;k<(1<<m);k++){
update(k,k<<1);
if(i>1&&!(k&(1<<(m-1))))
update(k,(k<<1)^(1<<m)^1);
if(j>1&&!(k&1))
update(k,(k<<1)^2^1);
}
}
has[m][n]=dp[cur][(1<<m)-1];
printf("%lld\n",has[m][n]);
}
return 0;
}

UVA11270 Tiling Dominoes(轮廓线动态规划)的更多相关文章

  1. UVA11270 Tiling Dominoes —— 插头DP

    题目链接:https://vjudge.net/problem/UVA-11270 题意: 用2*1的骨牌填满n*m大小的棋盘,问有多少种放置方式. 题解: 骨牌类的插头DP. 1.由于只需要记录轮廓 ...

  2. UVA11270 Tiling Dominoes

    \(\color{#0066ff}{ 题目描述 }\) 给定一个m×n的矩形网格,用1×2多米诺骨牌完全平铺. 请注意,即使一个平铺的旋转与另一个平铺相匹配,它们仍算作不同的平铺. 下面显示了一个平铺 ...

  3. [ACM_动态规划] 轮廓线动态规划——铺放骨牌(状态压缩1)

    Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...

  4. uva 11270 - Tiling Dominoes(插头dp)

    题目链接:uva 11270 - Tiling Dominoes 题目大意:用1∗2木块将给出的n∗m大小的矩阵填满的方法总数. 解题思路:插头dp的裸题,dp[i][s]表示第i块位置.而且该位置相 ...

  5. 【UVa】11270 Tiling Dominoes

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. leetcode动态规划题目总结

    Hello everyone, I am a Chinese noob programmer. I have practiced questions on leetcode.com for 2 yea ...

  7. 动态规划:插头DP

    这种动归有很多名字,插头DP是最常见的 还有基于连通性的动态规划 轮廓线动态规划等等 超小数据范围,网格图,连通性 可能算是状态压缩DP的一种变式 以前我了解的状压DP用于NP难题的小数据范围求解 这 ...

  8. 2013 ACM-ICPC亚洲区域赛南京站C题 题解 轮廓线DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4804 题目大意 给你一个 \(n \times m\) 的矩形区域.你需要用 \(1 \times 1 ...

  9. POJ2411 Mondriaan's Dream

    Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...

随机推荐

  1. 变量part2

    一 变量值具有三个特征:  1. id:变量值的唯一编号,内存地址不同id则不同  2. type:类型  3. value(值) #name='xia' #print(id(name)) #age= ...

  2. yii2开启事务

    public function actionAdd() { $model = new Goods(); $model->setScenario('insert'); if ($model-> ...

  3. GitHub 代码上传

    方法一 登录GitHub后,点击下面的图 New responsitory 按钮 或者点击绿色按钮 New repository,新建一个新建一个远程仓库(remote repository),点击后 ...

  4. 查看完整的 Unicode 字符集

    https://unicode-table.com/cn/ 这个链接是我想要查的 格式如下图 先放这里收藏,我也不知道怎么搜索

  5. python单下划线与双下划线的区别

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...

  6. 输入一串字符,检查是否可以组成friend

    """输入一串字符,检查是否可以组成friend""" from collections import Counter def foo(nu ...

  7. STO(Security Token Offering)证券型通证、代币发行介绍

    STO(Security Token Offering)证券型通证.代币发行介绍:STO(Security Token Offering)是一个新的融资概念.通过证券化的通证进行融资.早在2017年年 ...

  8. php获得可靠的精准的当前时间 ( 通过授时服务器 )

    有一种情形是这样子的,比如机票业务中的订票流程,我们需要一个非常可靠的当前时间来支持,尽管大多数服务器的时间是非常准确的,我们使用time()来获取的时间是可靠的,但未免会有不确切的情况,也有的服务器 ...

  9. ajax处理文件下载

    ajax中处理文件下载,可能大数会遇到我和一样的问题,什么问题呢?就是下载程序执行了,但是浏览器没有任何下载操作,这是为什么呢? 那是因为response原因,一般请求浏览器是会处理服务器输出的res ...

  10. GLSL写vertex shader和fragment shader

    0.一般来说vertex shader处理顶点坐标,然后向后传输,经过光栅化之后,传给fragment shader,其负责颜色.纹理.光照等等. 前者处理之后变成裁剪坐标系(三维),光栅化之后一般认 ...