Problem 2107 Hua Rong Dao

Accept: 503    Submit: 1054
Time Limit: 1000 mSec    Memory Limit : 32768
KB

Problem Description

Cao Cao was hunted down by thousands of enemy soldiers when he escaped from
Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while
Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one
1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be
regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is
empty.

There is only one Cao Cao. The number of Cross general, vertical general, and
soldier is not fixed. How many ways can all the people stand?

Input

There is a single integer T (T≤4) in the first line of the test data
indicating that there are T test cases.

Then for each case, only one integer N (1≤N≤4) in a single line indicates the
length of Hua Rong Dao.

Output

For each test case, print the number of ways all the people
can stand in a single line.

Sample Input

2
1
2

Sample Output

0
18

Hint

Here are 2 possible ways for the Hua Rong Dao 2*4.

Source

“高教社杯”第三届福建省大学生程序设计竞赛

 
题意:搜索多少种布阵方式,一定要有曹操。
思路:回溯dfs。
AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<set>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
#define N_MAX 7
#define MOD 1000000007
#define INF 0x3f3f3f3f
typedef long long ll;
int n, k;
bool vis[N_MAX][N_MAX],cc;
int ans = ;
void dfs(int x,int y) {
if (x==n) {//搜索结束
if (cc)ans++;//有曹操
return;
}
int xx=x, yy=y+;//下次要去的点
if (yy == ) {
xx++, yy = ;
} if (vis[x][y])dfs(xx, yy);
else {
for (int cs = ; cs < ;cs++) {
if (cs == &&!cc) {
if (x + < n&&y + < && !vis[x][y] && !vis[x + ][y] && !vis[x][y + ] && !vis[x + ][y + ]) {
cc = true;
vis[x][y] = vis[x + ][y] = vis[x][y + ] = vis[x + ][y + ] = true;
dfs(xx,yy);
vis[x][y] = vis[x + ][y] = vis[x][y + ] = vis[x + ][y + ] = false;
cc = false;
}
}
if (cs == ) {
if (x + < n && !vis[x][y] && !vis[x + ][y]) {
vis[x][y] = vis[x + ][y] = true;
dfs(xx,yy);
vis[x][y] = vis[x + ][y] = false;
}
}
if (cs == ) {
if (y + < && !vis[x][y] && !vis[x][y + ]) {
vis[x][y] = vis[x][y + ] = true;
dfs(xx, yy);
vis[x][y] = vis[x][y + ] = false;
}
}
if (cs == ) {
if (!vis[x][y]) {
vis[x][y] = true;
dfs(xx, yy);
vis[x][y] = false;
}
}
}
}
} int main() {
int t; cin >> t;
while(t--){
memset(vis, , sizeof(vis)); cc = ; ans = ;
cin >> n;
dfs(, );
cout << ans<<endl;
}
return ;
}

foj Problem 2107 Hua Rong Dao的更多相关文章

  1. FZOJ Problem 2107 Hua Rong Dao

                                                                                                        ...

  2. fzu 2107 Hua Rong Dao(状态压缩)

    Problem 2107 Hua Rong Dao Accept: 106    Submit: 197 Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  3. FZU 2107 Hua Rong Dao(dfs)

    Problem 2107 Hua Rong Dao Accept: 318 Submit: 703 Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...

  4. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  5. FZU 2107 Hua Rong Dao(暴力回溯)

    dfs暴力回溯,这个代码是我修改以后的,里面的go相当简洁,以前的暴力手打太麻烦,我也来点技术含量.. #include<iostream> #include<cstring> ...

  6. FOJ ——Problem 1759 Super A^B mod C

     Problem 1759 Super A^B mod C Accept: 1368    Submit: 4639Time Limit: 1000 mSec    Memory Limit : 32 ...

  7. FOJ Problem 1016 无归之室

     Problem 1016 无归之室 Accept: 926    Submit: 7502Time Limit: 1000 mSec    Memory Limit : 32768 KB  Prob ...

  8. FOJ Problem 1015 土地划分

    Problem 1015 土地划分 Accept: 823    Submit: 1956Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  9. foj Problem 2282 Wand

     Problem 2282 Wand Accept: 432    Submit: 1537Time Limit: 1000 mSec    Memory Limit : 262144 KB Prob ...

随机推荐

  1. 关于移动端video标签层级问题

    这是在微信中正常页面,就是用了一个原生video标签没做任何处理.然后顶部是固定页面顶端的,这个时候向上滑动页面时,会出现下图现象 这个时候正常人都会想到z-index问题,我也是这样想的,可惜很抱歉 ...

  2. 【PHP项目】伪静态规则

    伪静态规则写法RewriteRule-htaccess详细语法使用 2016年03月30日 16:53:59 阅读数:20340 伪静态实际上是利用php把当前地址解析成另一种方法来访问网站,要学伪静 ...

  3. C语言进阶——struct和union分析10

    struct的小秘密: C语言中的struct可以看作变量的集合 struct的问题:空结构体占用多大内存呢? 程序实例1: #include <stdio.h> struct TS { ...

  4. python面向对象(进阶篇)

    本篇将详细介绍Python 类的成员.成员修饰符.类的特殊成员. 类的成员: 类的成员可以分为三大类:字段(变量).方法.属性. 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对 ...

  5. 3,Linux入门

    操作系统的分类 Windows系列操作系统,Unix类操作系统,Linux类操作系统,Mac操作系统 提问:为什么要去学习Linux? 同学甲可能要问,超哥你介绍了这么多有关Linux的知识,但我还是 ...

  6. 变量存储类型(auto static extern)

    auto 动态存储类型变量(函数内部变量存储默认为 auto型) auto只用于函数内部定义,单片机在执行这个函数时为它分配内存地址,当函数执行完毕返回后,auto变量会被销毁,再次进入这个函数时,它 ...

  7. 【Pascal's Triangle II 】cpp

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...

  8. spring 笔记3: Spring 多环境配置文件切换

    使用Spring进行开发时,需要面对不同的运行环境,比如开发环境.测试环境.生产环境等.大多时候不同的环境需要不同的配置文件.网上很多资料都是使用Spring的Bean definition prof ...

  9. JMeter学习笔记(九) 参数化2--CSV Data Set Config

    2.CSV Data Set Config 1)添加 CSV Data Set Confi 2)配置CSV Data Set Config 3)添加HTTP请求,引用参数,格式 ${} 4)执行HTT ...

  10. Java进制间的转换

    最近学习了Java间的进制转换,记录下自己的学习心得,希望可以帮到前来查看的朋友们,如果有不懂的地方可以在下方评论留言,我们一起学习进步,只有自己足够强大才能弥补不足,多学习, 任意进制到十进制的转换 ...