本来直接一波状压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. python之简述上下文管理

    上下文管理器 原理 代码讲解 原理 上下文管理能保证资源会被正确回收,即保证退出步骤的执行.其用处最多的是,作为确保资源被正确回收的一种方式. 一种重复使用的 try-except-finally 结 ...

  2. 参数化取值策略Unique

    Unique:主要是强调取值的唯一性,如果到最后没有该值了,LR提供了其他解决方案,如图所示: 此处的下拉列表中提供了三种方式,具体如下: About Vuser,当取值次数超过参数的行数时,忽略脚本 ...

  3. PatentTips - Uncore thermal management

    BACKGROUND The field of invention relates to the computer sciences, generally, and, more specificall ...

  4. [ES6] Proxy & Reflect

    Proxy and Reflect API works nicely together. About how to use Proxy, check this post. Let's see abou ...

  5. [React] Reference a node using createRef() in React 16.3

    In this lesson, we look at where we came from with refs in React. Starting with the deprecated strin ...

  6. linux 下password加密程序(能够用于替换shadow文件里的用户password)

    源代码例如以下: #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]){ if(arg ...

  7. 遗传奥秘的伟大揭秘者:J.Watson

    J.Watson的近照: 人们公认,揭秘生命体的遗传奥秘(DNA)是二十世纪最伟大的科技成果之中的一个,或许就是人类最伟大的科技进步(而不是"之中的一个"). 上世纪是人类做出伟大 ...

  8. spring batch(一):基础部分

    spring batch(一):基础部分 博客分类: Spring java   spring batch 官网: http://www.springsource.org/spring-batch 下 ...

  9. JTCalendar

    JTCalendar是一款简易使用而且能够自己定义事件的日历.包含圈点标识的颜色等都能够自己定义.demo中还提供了转换日历模式的样例. 效果图: " style="margin: ...

  10. java.lang.ClassNotFoundException: org.objectweb.asm.ClassWriter

    转自:https://www.cnblogs.com/yfceshi/p/6814802.html Caused by: javax.xml.ws.WebServiceException: java. ...