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. HTML+CSS : 笔记整理(3 移动端布局简单了解)

    流体布局:宽度用百分比,计算真实宽度用函数 : width: calc(25% - 4px); box-sizing: 1.content-box:默认计算方式 ,宽度和高度分别应用到元素的内容框.在 ...

  2. Flask初学者:视图函数/方法返回值(HTML模板/Response对象)

    返回HTML模板:使用“from flask import render_template”,在函数中传入相对于文件夹“templates”HTML模板路径名称字符串即可(默认模板路径),flask会 ...

  3. 匿名函数lambda python

    lambda 的主体是一个表达式,不是一个代码块lambda 只有一行,仅仅能在lambda表达式种封装有限的逻辑进去匿名函数:需要一个函数,而又不想动脑筋去想名字 #普通函数的定义 def f(a, ...

  4. Windows Server 2008 R2 可能会碰到任务计划无法自动运行的解决办法

    在做Windows Server 2008R2系统的计划任务时使用到了bat脚本,手动启动没问题,自动执行缺失败,代码:0x2. 将“操作”的“起始于”进行设置了bat脚本的目录即可.

  5. python-11多线程

    1-多任务可以由多进程完成,也可以由一个进程内的多线程完成. 1.1多线程代码示例 import time, threading def loop(): print("thread %s i ...

  6. INSERT⋯ACCEPTING_DUPLICATE_KEYS

    使用ACCEPTING DUPLICATE KEYS时,当插入时发现这条记录已存在时,那么这条记录将不会被insert,后续记录继续执行insert

  7. 2 实现第一个Django网站 博客

    -1.理解上下文 render()渲染 request  url传来的reuqest x.html 制定返回的模板名称 context 上下文    数据库中 替换数据 0.大框架 1.创建模板 (1 ...

  8. Android 导出traces.txt 遇到的坑

    我一直以为traces.txt 导出需要root .因为每当我 cd data ll 然后就会告诉我 Permission denied 后来我问同事,怎么导出traces.txt 文件.同事说很简单 ...

  9. Android学习记录(4)—在java中学习多线程下载的基本原理和基本用法①

    多线程下载在我们生活中非常常见,比如迅雷就是我们常用的多线程的下载工具,当然还有断点续传,断点续传我们在下一节来讲,android手机端下载文件时也可以用多线程下载,我们这里是在java中写一个测试, ...

  10. IDEA调试快捷键

    F9            resume programe 恢复程序 F8            Step Over 相当于eclipse的f6      跳到下一步 Ctrl+Shift+F,全局查 ...