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
...
随机推荐
- hive sql 学习笔记
1.coalesce 语法: COALESCE ( expression [ ,...n ] ) 参数: expression 任何类型的表达式. 返回类型: 返回数据类型优先级最高的 express ...
- destoon添加修改会员信息时,信息丢失
最近做一destoon项目,因注册字段太多,分了几个步骤.分几个页面来修改公司信息.发现有时候修改时以前保存的字段莫名丢失.. 经查是 因为member.class.php add 和 edit时, ...
- 【mysql】【转发】Cannot proceed because system tables used by Event Scheduler were found damaged at server start
本地:mac 10.12.3 mysql 5.6 远程:linux 7.3 mysql 5.7.18. (远程数据库yum安装,又5.6升级到5.7) 步骤:从本地数据库导出数据到远 ...
- drf 视图功能
视图 drf提供的视图功能 自己的第一次封装 #一个功能写成一个类,方便组合,只要继承它就可以有这个功能 #将功能都写在一个类中,可控性就会变差 from book.myserializers imp ...
- python-matplotlib-lec0
直奔主题吧..以下是对matplotlib画图的简单讲解,代码已测试. win7 + pycharm + python 2.7 参考文档: http://old.sebug.net/paper/boo ...
- centos7 安装显卡驱动方法
方法一: 首先需要添加一个第三方的源ELRepo.这个源支持RED HAT系的Linux系统,主要是提供一些硬件的驱动程序.这个源的主页如下: http://elrepo.org/tiki/tiki- ...
- 【草稿】JS中如何操作时间
如何声明时间变量 如何设置时间变量的时.分.秒.毫秒 如何根据字符串变量,声明指定的时间变量 如何比较两个时间变量 代码如下: $(function () { var d = new Date(); ...
- private virtual in c++
source from http://blog.csdn.net/steedhorse/article/details/333664 // Test.cpp #include <iostream ...
- 15年多校第一场七题hdu5294
要做这题,先要明白图的割,说白了就是 为了让原点无法到汇点要删几条边(之所以叫割,就是在图面上切一刀,减掉最小的边是原点和汇点成为两个集合),想到了割先放着一会用. 题中说只有沿最短路走才有可能追上, ...
- 引用&符号详解
变量的引用 PHP 的引用允许你用两个变量来指向同一个内容. 例一: <?php $a="2010"; $b =&$a; echo $a;//这里输出:2010 ec ...