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 ...
随机推荐
- scrapy--Beautyleg
很早就开始关注:Beautyleg 高清丝袜美腿.关注之后开始觉得打开了新世界的大门,如果有相同观点的,那么你很有品味.说真的,学习爬虫的动力之一就是想把里面的图片爬取下来.哈哈哈!!! 给大家放点爬 ...
- php-5.6.26源代码 - opcode处理器,“乘法opcode”处理器
// opcode处理器 - 运算符怎么执行: “*” 乘法opcode处理器 static int ZEND_FASTCALL ZEND_MUL_SPEC_CONST_CONST_HANDLER(Z ...
- HyperLedger Fabric ca 1.2 正式环境部署
生成一个根CA(RootCA),在根CA下3个中间CA(IntermediaCA). 1. 运行和配置RootCA服务#cd /opt/gopath/src/github.com/hyperledge ...
- html_outputer.py
coding=UTF-8 # HTML输出器 import sys class htmlOutputer(): def __init__(self): self.data = [] def colle ...
- Mysql 表转换成 Sqlite表
目前的转换仅仅支持对没有外键的Mysql数据表 准备: 下载安装 Sqlite Expert 软件 一 获取Mysql中的.sql文件,获取过程省略可以直接导出sql文件 二 在Sqlite Expe ...
- MySQL之查询性能优化(三)
MySQL查询优化器的局限性 MySQL的万能“嵌套循环”并不是对每种查询都是最优的.不过还好,MySQL查询优化只对少部分查询不适用,而且我们往往可以通过改写查询让MySQL高效地完成工作. 关联子 ...
- leetcode 208. 实现 Trie (前缀树)
实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作. 示例: Trie trie = new Trie(); trie.insert(" ...
- springboot10 framwork
一.Spring介绍 Spring 是位于业务逻辑层的框架. 优点很多(无缝对接前后层的框架.提供AOP的支持 , 和以前的 Sstruts . Hibernate 组合成了一套框架组合 SSH .现 ...
- 网络--OSI七层模型详解
OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 . 完成中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...
- JavaWeb笔记(八)JQuery
三个版本 1.x:兼容 ie678,使用最为广泛的,官方只做BUG维护, 功能不再新增.因此一般项目来说,使用1.x版本就可以了 最终版本:1.12.4 2.x:不兼容ie678,很少有人使用,官方只 ...