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. 一行代码搞定checkbox全选和全不选

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  2. pyhton——logging日志模块的学习

    https://www.cnblogs.com/yyds/p/6901864.html 本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模 ...

  3. [CodeForces940E]Cashback(set+DP)

    Description Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is ...

  4. STM8S PWM输出停止后 IO口电平输出

    STM8S有许多定时器支持PWM输出,但在停止定时器后,IO口电平到底是多少呢?或高或低. 因此,为了确定PWM停止输出电平后其对应的值是多少,我们在停止PWM输出时需要对CCMR1寄存器进行设置. ...

  5. 十三、MySQL之IDE工具介绍及数据备份

    一.IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 二.MySQL数据备份 # ...

  6. 绿盟python测试实习面试

    1.简历问题 低级错误:时间写错 最近好像越来越马大哈了,总是犯低级错误. 上次的开题报告首页,这次的时间,每次都有小问题,确是大毛病 到底哪里出错了 2 RHCE证书好像没有用 面试官根本就不懂这个 ...

  7. 3195: [Jxoi2012]奇怪的道路

    3195: [Jxoi2012]奇怪的道路 链接 思路: 因为一个点只会和它前后k个点连边,所以,记录下每个点的前k个点和它自己(共k+1个点)的状态,1表示奇数,0表示偶数. dp[i][j][s] ...

  8. 《Cracking the Coding Interview》——第8章:面向对象设计——题目9

    2014-04-23 23:57 题目:如何设计一个内存文件系统,如果可以的话,附上一些代码示例. 解法:很遗憾,对我来说不可以.完全没有相关经验,所以实在无从入手.这题目应该和工作经验相关吧? 代码 ...

  9. PL/SQL 循环语句

    1.基本 LOOP 循环语句 语法: LOOP 语句序列; END LOOP; 其中,语句序列中需要一个EXIT语句或一个EXIT WHEN语句来中断循环. 实例: DECLARE x ) :; BE ...

  10. selenium 使用谷歌浏览器模拟wap测试

    /** * 使用谷歌浏览器模拟手机浏览器 * @param devicesName * @author xxx * 创建时间:2017-06-15,更新时间:2017-06-15 * 备注 */ pu ...