本来直接一波状压dpAC的

#include<cstdio>
#include<cstring>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std; typedef long long ll;
ll dp[50][10];
int path[15][2], p, n, m = 3; void dfs(int l, int now, int pre)
{
if(l > m) return;
if(l == m)
{
path[p][0] = pre;
path[p++][1] = now;
return;
} dfs(l + 1, (now << 1) | 1, pre << 1);
dfs(l + 1, now << 1, (pre << 1) | 1);
dfs(l + 2, (now << 2) | 3, (pre << 2) | 3);
} int main()
{
dfs(0, 0, 0);
while(~scanf("%d", &n) && n != -1)
{
memset(dp, 0, sizeof(dp));
dp[0][(1 << m) - 1] = 1;
_for(i, 1, n)
REP(j, 0, p)
dp[i][path[j][1]] += dp[i-1][path[j][0]];
printf("%lld\n", dp[n][(1 << m) - 1]);
}
return 0;
}

然后闲着无聊想用滚动数组优化一下,虽然说对于这道题完全没必要

然后就发现了问题

每次使用的时候要清空这一行的值

因为这道题的状态转移是+=, 以前都是=,所以值可以直接覆盖。

还有一定要i++之后t再改,我一开始是写j++后t就改,然后就连样例都过不了,调了好久才发现

#include<cstdio>
#include<cstring>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std; typedef long long ll;
ll dp[2][10];
int path[15][2], p, n, m = 3; void dfs(int l, int now, int pre)
{
if(l > m) return;
if(l == m)
{
path[p][0] = pre;
path[p++][1] = now;
return;
} dfs(l + 1, (now << 1) | 1, pre << 1);
dfs(l + 1, now << 1, (pre << 1) | 1);
dfs(l + 2, (now << 2) | 3, (pre << 2) | 3);
} int main()
{
dfs(0, 0, 0);
while(~scanf("%d", &n) && n != -1)
{
memset(dp, 0, sizeof(dp));
int t = 0;
dp[t][(1 << m) - 1] = 1; t ^= 1;
_for(i, 1, n)
{
REP(j, 0, p) dp[t][path[j][1]] = 0; //这一行是关键
REP(j, 0, p)
dp[t][path[j][1]] += dp[t^1][path[j][0]];
t ^= 1;
}
printf("%lld\n", dp[t^1][(1 << m) - 1]);
}
return 0;
}

poj 2663 Tri Tiling (状压dp+多米诺骨牌问题+滚动数组反思)的更多相关文章

  1. poj 3420 Quad Tiling (状压dp+多米诺骨牌问题+矩阵快速幂)

    还有这种操作?????? 直接用pre到now转移的方式构造一个矩阵就好了. 二进制长度为m,就构造一个长度为1 << m的矩阵 最后输出ans[(1 << m) - 1][( ...

  2. poj2411 Mondriaan's Dream (状压dp+多米诺骨牌问题)

    这道题的解析这个博客写得很好 https://blog.csdn.net/shiwei408/article/details/8821853 大致意思就是我们可以只处理两行之间的关系,然后通过这两个关 ...

  3. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  4. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  5. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  6. poj 3254Corn Fields (入门状压dp)

    Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn fo ...

  7. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  8. POJ 2923 Relocation(状压DP)题解

    题意:有2辆车运货,每次同时出发,n(<10),各自装货容量c1 c2,问最少运几次运完. 思路:n比较小,打表打出所有能运的组合方式,用背包求出是否能一次运走.然后状压DP运的顺序. 代码: ...

  9. POJ 2663 Tri Tiling

                                                                                    Tri Tiling   Time Li ...

随机推荐

  1. PHP图片验证码处理

  2. 正确判断js数据类型 总结记录

    正确判断js数据类型 总结记录 判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. 三方库. js六大数据类型 number: 数 ...

  3. some untracked working tree files问题解决

    我使用的是idea,情境是在使用git同步代码的时候,出现的错误. 我这里报错是在右上角的显示信息,其中有一个show view的可点击连接 我点击之后将上面展示的文件删除之后重新同步代码,成功.

  4. properties 乱码问题

    File --> Others Settings --> Default Settings

  5. 日志log配置理解

    实际生产中,每天都有大量的日志生成,单个文件(FileAppender)已经不能满足要求,RollingFileAppender继承了FileAppender,并提供了更多的功能: 每天生成一个日志文 ...

  6. 【MongoDB】The basic operation of Index in MongoDB

    In the past four blogs, we attached importance to the index, including description and comparison wi ...

  7. Docker Compose + Spring Boot + Nginx + Mysql

    Docker Compose + Spring Boot + Nginx + Mysql 实践 我知道大家这段时间看了我写关于 docker 相关的几篇文章,不疼不痒的,仍然没有感受 docker 的 ...

  8. svn插件失效

    安装其他插件后,可能出现SVN插件失效了,在eclipse中完全找不到SVN的任何操作选项,此时可尝试通过以下办法解决: 把eclipse/configuration目录下的org.eclipse.u ...

  9. Centos7 minimal 系列之NAT联网(一)

    一.安装 参考:http://m.blog.csdn.net/qq_24879495/article/details/77838512 二.解决不能联网问题 打开网络共享中心,设置虚拟网卡 编辑虚拟机 ...

  10. User_Login_Register_Shopping+装饰器 3.0

    #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2018/5/27 0027 14:07# @Author : Anthony.Waa# @ ...