FZOJ 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
can stand in a single line.
Sample Input
1
2
Sample Output
18
Hint
Here are 2 possible ways for the Hua Rong Dao 2*4.
#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的更多相关文章
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- fzu 2107 Hua Rong Dao(状态压缩)
Problem 2107 Hua Rong Dao Accept: 106 Submit: 197 Time Limit: 1000 mSec Memory Limit : 32768 K ...
- FZU 2107 Hua Rong Dao(dfs)
Problem 2107 Hua Rong Dao Accept: 318 Submit: 703 Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- FZU 2107 Hua Rong Dao(暴力回溯)
dfs暴力回溯,这个代码是我修改以后的,里面的go相当简洁,以前的暴力手打太麻烦,我也来点技术含量.. #include<iostream> #include<cstring> ...
- FZOJ Problem 2219 StarCraft
...
- FZOJ Problem 2150 Fire Game
...
- FZOJ Problem 2148 Moon Game
Proble ...
- FZOJ Problem 2110 Star
...
随机推荐
- (转发)InputAccessoryView的使用方法
转自:http://blog.sina.com.cn/s/blog_45e2b66c01015we9.html UITextFields and UITextViews have an inputAc ...
- 2829: 高精A+B [1*+]
题目描述 输入A和B,计算A+B的值 Input 两行数据,分别是A和B 0<=A<=1E200 0<=B<=10^200 Output A+B的结果 Sample Input ...
- vc文件操作汇总—支持wince
一.判断文件及文件夹是否存在 // 判断文件是否存在 BOOL IsFileExist(const CString& csFile) { DWORD dwAttrib = GetFileAtt ...
- gradle更换国内镜像、配置本地仓库地址
gradle更换国内镜像,安装包解压后init.d文件夹下面创建init.gradle文件,内容如下 allprojects{ repositories { def REPOSITORY_URL = ...
- [BZOJ] 1127: [POI2008]KUP
似曾相识的感觉 考虑另一个判断问题,给定一个k,问这个k是否可行 存在矩形和\(sum>2k\),则该矩阵不对判定做出贡献 存在矩形和\(sum\in [k,2k]\),则我们找到了一个解 于是 ...
- 编译安装 nginx php swoole
安装之前先 准备环境 yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel 然后 ...
- Linux-CentOS6.9启动流程排错
1 . CentOS6.9启动流程 POST 加电自检,是BIOS功能的一个主要部分.负责完成对CPU.主板.内存.硬盘子系统.显示子系统.串并行接口.键盘.CD-ROM光驱等硬件情况的检测. Boo ...
- day2-python 登录
# username = 'niuhanyang' # 写一个判断登录的程序: # 输入: username # password # 最大错误次数是3次,输入3次都没有登录成功,提示错误次数达到上限 ...
- python 数据结构与算法之排序(冒泡,选择,插入)
目录 数据结构与算法之排序(冒泡,选择,插入) 为什么学习数据结构与算法: 数据结构与算法: 算法: 数据结构 冒泡排序法 选择排序法 插入排序法 数据结构与算法之排序(冒泡,选择,插入) 为什么学习 ...
- Linux学习-Linux 的开机流程分析
开机流程一览 系统开机的经过可以汇整成底下的流程的: 加载 BIOS 的硬件信息与进行自我测试,并依据设定取得第一个可开机的装置; 读取并执行第一个开机装置内 MBR 的 boot Loader (亦 ...