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. Golang glog使用详解

    golang/glog 是 C++ 版本 google/glog 的 Go 版本实现,基本实现了原生 glog 的日志格式.在 Kuberntes 中,glog 是默认日志库. glog 的使用与特性 ...

  2. [BZOJ4327]:[JZOI2012]玄武密码(AC自动机)

    题目传送门 题目描述: 在美丽的玄武湖畔,鸡鸣寺边,鸡笼山前,有一块富饶而秀美的土地,人们唤作进香河.相传一日,一缕紫气从天而至,只一瞬间便消失在了进香河中.老人们说,这是玄武神灵将天书藏匿在此.  ...

  3. Dojo常用函数

    1.array函数:和原生的JavaScript中的数组遍历方法forEach方法用法相同 define(['dojo/_base/declare', "dojo/_base/array&q ...

  4. 『jQuery』.html(),.text()和.val()的概述及使用--2015-08-11

    如何使用jQuery中的.html(),.text()和.val()三种方法,用于读取,修改元素的html结构,元素的文本内容,以及表单元素的value值的方法   本节内容主要介绍的是如何使用jQu ...

  5. Convert HTML Entities-freecodecamp算法题目

    Convert HTML Entities 1.要求 将字符串中的字符 &.<.>." (双引号), 以及 ' (单引号)转换为它们对应的 HTML 实体. 2.思路 利 ...

  6. Codevs1081 线段树练习 2

    题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ...

  7. 共享服务-FTP基础(一)

    介绍:文件传输协议FTP 两种模式:服务器角度 主动(PORT style):服务器主动连接 命令(控制):客户端:随机port --- 服务器:tcp21 数据:客户端:随机port ---服务 ...

  8. Unity基础-脚本的加载与编译顺序

    脚本的加载与编译顺序 C#是以Assembly(汇编集)为一个基本单元组织代码的,dll就是一个assembly,dll之间有加载以来顺序 Assets/*.dll Stamdard Assets/* ...

  9. thinkcmf5更新模板代码分析,解决模板配置json出错导致数据库保存的配置项内容丢失问题

    private function updateThemeFiles($theme, $suffix = 'html') { $dir = 'themes/' . $theme; $themeDir = ...

  10. UVa - 1592 Database(STL,优化)

    给一个n行m列的数据库表格,问有没有两个行 r1,r2 和 c1,c2,满足(r1,r2)的元素=(c1,c2)的元素. n≤10000,m≤10. 直接枚举4个肯定会T的.可以只枚举c1 c2,然后 ...