Problem 2107 Hua Rong Dao

Accept: 401    Submit: 853
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.

 
 
题意:在由方格组成的大小为N*4的矩阵内排行军队伍,曹操占四个方格且必须存在,竖向的将军占2*1的长方形矩阵,横向将军占1*2的长方形矩阵,其余小兵占一单位方格,现在问总共能找到多少种行军队伍排列的方案,每种方案都要求将N*4的矩阵填充满。
思路:深度优先搜索,直至所有的小方块空间都被队伍填充。
AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
int N;
int vis[][];
bool flag = ;
int num ;
bool judge(int x,int y) {
if (x >= && x < N&&y >= && y < &&!vis[x][y]) {//!!!
return true;
}
return false;
} void dfs(int count) {
if (count == N * && flag) { num++; return; }
if (count >= N * )return;
for (int i = ; i < N; i++) {
for (int j = ; j < ; j++) {
if (judge(i, j) && judge(i + , j) && judge(i, j + ) && judge(i + , j + ) && !flag) {
flag = ;
vis[i][j] = vis[i + ][j] = vis[i][j + ] = vis[i + ][j + ] = ;
dfs(count + );
flag = ;
vis[i][j] = vis[i + ][j] = vis[i][j + ] = vis[i + ][j + ] = ;
}
if (judge(i, j) && judge(i + , j)) {
vis[i][j] = vis[i + ][j] = ;
dfs(count + );
vis[i][j] = vis[i + ][j] = ;
}
if (judge(i, j) && judge(i, j + )) {
vis[i][j] = vis[i][j + ] = ;
dfs(count + );
vis[i][j] = vis[i][j + ] = ;
}
if (judge(i, j)) {
vis[i][j] = ;
dfs(count + );
vis[i][j] = ;
return;//!!!!
}
}
}
} int main() {
int T;
scanf("%d",&T);
while (T--) {
scanf("%d",&N);
num =flag= ;
memset(vis,,sizeof(vis));
dfs();
printf("%d\n",num);
}
return ;
}
 

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

  1. foj Problem 2107 Hua Rong Dao

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

  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. FZOJ Problem 2219 StarCraft

                                                                                                        ...

  7. FZOJ Problem 2150 Fire Game

                                                                                                        ...

  8. FZOJ Problem 2148 Moon Game

                                                                                                  Proble ...

  9. FZOJ Problem 2110 Star

                                                                                                        ...

随机推荐

  1. Render渲染函数和JSX

    1.Render函数:render是用来替换temlate的,需要更灵活的模板的写法的时候,用render. 官网API地址:https://cn.vuejs.org/v2/guide/render- ...

  2. 用C#(ASP.Net)在Exchange Server环境下发送邮件

    普通的邮件, 用System.Net.Mail 类 或 System.Web.Mail 类 处理即可, 但是Exchange Server 环境下, 这两个类起不了作用-------至少目前我看到的情 ...

  3. git使用stash存储相关操作

    git stash  将当前修改存储起来 git stash apply 恢复最近一次存储 git stash apply stash@{2} 恢复某一次存储 git stash list 查看存储列 ...

  4. 【原】基于matlab的蓝色车牌定位与识别---绪论

    本着对车牌比较感兴趣,自己在课余时间摸索关于车牌的定位与识别,现将自己所做的一些内容整理下,也方便和大家交流. 考虑到车牌的定位涉及到许多外界的因素,因此有必要对车牌照的获取条件进行一些限定: 一.大 ...

  5. Windows7设置局域网文件共享

    首先要实现共享必须设置共享的机器与访问共享的机器在同一个工作组中. 右键桌面上的计算机图标=>属性 如果不一样的话,就需要点击[更改设置] 右键要共享的文件或者文件夹,点击[共享]打开共享标签: ...

  6. Windows10 关闭自动更新

    win+R调出运行窗口: 输入services.msc,查找 跳出服务窗口,点击windows update设置禁用即可 Windows Update Medic Service没办法禁用,需要采用其 ...

  7. Voyager的安装及配置文件

    使用代理服务器安装laravel http_proxy=http://localhost:1080 composer create-project --prefer-dist laravel/lara ...

  8. CodeForces 703A Mishka and trip

    Description Little Mishka is a great traveller and she visited many countries. After thinking about ...

  9. STM8S与IAR程序常用错误

    一.IAR中的重复定义问题 在自己写头文件时,要记得将常量定义在.c文件中,如果将常量定义在.h文件中,当在main.c或者其他地方包含该头文件时,会将头文件中的常量定义包 含到main.c中,同时, ...

  10. foreach遍历数组的表格

    <?php /** * * @authors Your Name (you@example.org) * @date 2017-03-17 19:06:19 * @version $Id$ */ ...