foj Problem 2107 Hua Rong Dao
Accept: 503 Submit: 1054
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.

Source
“高教社杯”第三届福建省大学生程序设计竞赛
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<set>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
#define N_MAX 7
#define MOD 1000000007
#define INF 0x3f3f3f3f
typedef long long ll;
int n, k;
bool vis[N_MAX][N_MAX],cc;
int ans = ;
void dfs(int x,int y) {
if (x==n) {//搜索结束
if (cc)ans++;//有曹操
return;
}
int xx=x, yy=y+;//下次要去的点
if (yy == ) {
xx++, yy = ;
} if (vis[x][y])dfs(xx, yy);
else {
for (int cs = ; cs < ;cs++) {
if (cs == &&!cc) {
if (x + < n&&y + < && !vis[x][y] && !vis[x + ][y] && !vis[x][y + ] && !vis[x + ][y + ]) {
cc = true;
vis[x][y] = vis[x + ][y] = vis[x][y + ] = vis[x + ][y + ] = true;
dfs(xx,yy);
vis[x][y] = vis[x + ][y] = vis[x][y + ] = vis[x + ][y + ] = false;
cc = false;
}
}
if (cs == ) {
if (x + < n && !vis[x][y] && !vis[x + ][y]) {
vis[x][y] = vis[x + ][y] = true;
dfs(xx,yy);
vis[x][y] = vis[x + ][y] = false;
}
}
if (cs == ) {
if (y + < && !vis[x][y] && !vis[x][y + ]) {
vis[x][y] = vis[x][y + ] = true;
dfs(xx, yy);
vis[x][y] = vis[x][y + ] = false;
}
}
if (cs == ) {
if (!vis[x][y]) {
vis[x][y] = true;
dfs(xx, yy);
vis[x][y] = false;
}
}
}
}
} int main() {
int t; cin >> t;
while(t--){
memset(vis, , sizeof(vis)); cc = ; ans = ;
cin >> n;
dfs(, );
cout << ans<<endl;
}
return ;
}
foj Problem 2107 Hua Rong Dao的更多相关文章
- FZOJ Problem 2107 Hua Rong Dao
...
- 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> ...
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- FOJ Problem 1016 无归之室
Problem 1016 无归之室 Accept: 926 Submit: 7502Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FOJ Problem 1015 土地划分
Problem 1015 土地划分 Accept: 823 Submit: 1956Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- foj Problem 2282 Wand
Problem 2282 Wand Accept: 432 Submit: 1537Time Limit: 1000 mSec Memory Limit : 262144 KB Prob ...
随机推荐
- request中的那些方法到底是干什么的?
最近做Java Web项目,在.jsp页面和servlet之间request和response还是有些混淆,查阅了一些资料,总结如下,方便以后使用: 首先,servlet接口是最基本的,提供的五个方法 ...
- laravels -- Swoole加速php
LaravelS是一个胶水项目,用于快速集成Swoole到Laravel,然后赋予它们更好的性能.更多可能性. 环境 : ubuntu16 + nginx + php7.1 + LaravelS搭建高 ...
- Apache2服务配置ubuntu16.04+django1.11
话不多说直接上步骤 环境 Ubuntu 16.04 Python 3.5.2 Django 1.11 Apache 2.4 1.Apache2安装 sudo apt-get install apach ...
- django-simple-captcha
在注册页面生成验证码的时候,出现错误如下: build_attrs() takes from 1 to 2 positional arguments but 3 were given, 不知道为什么报 ...
- NOIP PJ游记
Day -1 感觉自信满满,一等奖应该稳了,毕竟初一时我这么菜都拿了二等奖,然后就睡觉了... Day 1 在大巴上玩元气骑士可开心了,车上欢欢喜喜,到了考场,一眼看题,以为很简单. T1硬模拟... ...
- [Bzoj1034][ZJOI2008]泡泡堂BNB(贪心)
Description 题目链接 Solution 这题就是一个贪心, 如果最弱的能赢对方最弱的就赢 否则最强的能赢对面最强的就赢 否则最弱的换对面最强 Code #include <cstdi ...
- 20145202马超 《Java程序设计》第九周学习总结
JDBC 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找. JDBC(Java DataBase Connectivity)是Java联机数据库 ...
- Maven项目Update Project自动恢复为JRE1.5的问题
问题: 使用Eclipse建立Maven项目的时候,JDK默认为1.5在用户使用Config Build Path更新为最新JRE库比如1.8或者1.7的后,Maven项目显示JRE1.8 or 1. ...
- linux udp c/s
一.UDP C/S编程的步骤如下图所示 二.与TCP C/S通信的区别在于:服务端没有设置监听和等待连接的过程.客户端没有连接服务端的过程.基于UDP的通信时不可靠地,面向无连接的,发送的数据无法确切 ...
- Python作业--登录接口
作业需求: 编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 实现思路: 1.从文件获取用户名密码 2.判断是否在黑名单中 3.验证用户名密码 成功:输出认证成功 错误:判断验证次 ...