博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
阅读量:5088 次
发布时间:2019-06-13

本文共 2649 字,大约阅读时间需要 8 分钟。

 Hua Rong Dao
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
   

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

212

Sample Output

018

Hint

Here are 2 possible ways for the Hua Rong Dao 2*4.

 
/*/题意:华容道,N*4的格子,N=[1,4],一个曹操 2*2 有 2*1、1*2和1*1的士兵,问有多少中放法。一开始不知道自己怎么想的,看一下数据这么小,而且1,2,3很容易就推出来了,以为可以推出来,【MDZZ】结果在N==4这种情况下爆炸了。。下面进入正题。直接DFS暴力。如果怕超时可以打表,实际上不会。AC代码:/*/
#include"algorithm"#include"iostream"#include"cstring"#include"cstdlib"#include"cstdio"#include"string"#include"vector"#include"stack"#include"queue"#include"cmath"#include"map"using namespace std;typedef long long LL ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define FK(x) cout<<"["<
<<"]\n"#define memset(x,y) memset(x,y,sizeof(x))#define memcpy(x,y) memcpy(x,y,sizeof(x))#define bigfor(T) for(int qq=1;qq<= T ;qq++)int n;int ans,flag;bool vis[10][10];bool check(int x,int y) { if(x<0||y<0||x>=n||y>=4||vis[x][y])return 0; return 1;}void DFS(int x) { if(x==4*n&&flag==1) { ans++; return ; } if(x>=4*n) { return ; } for(int i=0; i<4; i++) { for(int j=0; j<4; j++) { if(check(i,j)&&check(i+1,j)&&check(i,j+1)&&check(i+1,j+1)&&!flag) { vis[i][j]=vis[i+1][j]=vis[i][j+1]=vis[i+1][j+1]=1; flag=1; DFS(x+4); vis[i][j]=vis[i+1][j]=vis[i][j+1]=vis[i+1][j+1]=0; flag=0; } if(check(i,j)&&check(i+1,j)) { vis[i][j]=vis[i+1][j]=1; DFS(x+2); vis[i][j]=vis[i+1][j]=0; } if(check(i,j)&&check(i,j+1)) { vis[i][j]=vis[i][j+1]=1; DFS(x+2); vis[i][j]=vis[i][j+1]=0; } if(check(i,j)) { vis[i][j]=1; DFS(x+1); vis[i][j]=0; return ; } } }}//int _ans[5]={0,0,18,284,4862};int main() { int T;S scanf("%d",&T); bigfor(T) { scanf("%d",&n); memset(vis,0); flag=0; ans=0; DFS(0); printf("%d\n",ans); } return 0;}
 

  

 

 

转载于:https://www.cnblogs.com/HDMaxfun/p/5789506.html

你可能感兴趣的文章
django里的http协议
查看>>
判断一个文件是否是指定后缀名的文件
查看>>
随机时间.排序,分出时 分 秒
查看>>
MyBatis开发环境搭建
查看>>
100阶乘末尾有多少个零
查看>>
Extjs fieldText内容
查看>>
安装php7.2
查看>>
fiex布局实例
查看>>
构建之法阅读笔记01
查看>>
Item 2:Prefer C++-style casts.(More Effective C++)
查看>>
Delegation and Core Location(Chapter 4 of iOS Programming: The Big Nerd Ranch Guide)
查看>>
HDU 4001 To Miss Our Children Time dp
查看>>
mina 通讯框架
查看>>
vue表格业务
查看>>
maven 配置说明
查看>>
js接收网页参数
查看>>
linux之查看端口占用
查看>>
[原创]浅谈互联网金融测试平台规划
查看>>
什么是网关及网关作用(转)
查看>>
skymvc网站测试之mysql数据生成
查看>>