惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
K
Kaspersky official blog
A
Arctic Wolf
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 热门话题
N
News | PayPal Newsroom
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
W
WeLiveSecurity
Know Your Adversary
Know Your Adversary
博客园 - Franky
T
Tenable Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Help Net Security
Help Net Security
WordPress大学
WordPress大学
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security Affairs
J
Java Code Geeks
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
O
OpenAI News
The Cloudflare Blog
月光博客
月光博客
Google Online Security Blog
Google Online Security Blog
V
V2EX
罗磊的独立博客
美团技术团队
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏

博客园 - ZefengYao

Markdown 入门与 Word 使用指南 关于崩溃报告的日志以及dump文件 hdu 6223 Infinite Fraction Path 2017南宁现场赛E The Champion ACM-ICPC 2018 南京赛区网络预赛 Sum c语言几个字符串处理函数的简单实现 各种类型排序的实现及比较 随机洗牌算法Knuth Shuffle和错排公式 两个栈实现队列 面试杂题 面试题——栈的压入、弹出顺序 C++ 智能指针的简单实现 openGL初学函数解释汇总 foj Problem 2282 Wand UVA-1400 Ray, Pass me the dishes! 《挑战程序设计竞赛》 利用后缀数组求最长回文串 Uva 11174 Stand in a Line UVA 11375 Matches poj 3729 Facer’s string
foj Problem 2107 Hua Rong Dao
ZefengYao · 2018-06-09 · via 博客园 - ZefengYao

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

For each test case, print the number of ways all the people can stand in a single line.

Sample Input

2 1 2

Sample Output

0 18

Hint

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

Source

“高教社杯”第三届福建省大学生程序设计竞赛 

题意:搜索多少种布阵方式,一定要有曹操。

思路:回溯dfs。

AC代码:

#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 = 0;
void dfs(int x,int y) {
    if (x==n) {//搜索结束
        if (cc)ans++;//有曹操
        return;
    }
    int xx=x, yy=y+1;//下次要去的点
    if (yy == 4) {
        xx++, yy = 0;
    }
    
    if (vis[x][y])dfs(xx, yy);
    else {
        for (int cs = 0; cs < 4;cs++) {
            if (cs == 0&&!cc) {
                if (x + 1 < n&&y + 1 < 4 && !vis[x][y] && !vis[x + 1][y] && !vis[x][y + 1] && !vis[x + 1][y + 1]) {
                    cc = true;
                    vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = true;
                    dfs(xx,yy);
                    vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = false;
                    cc = false;
                }
            }
            if (cs == 1) {
                if (x + 1 < n && !vis[x][y] && !vis[x + 1][y]) {
                    vis[x][y] = vis[x + 1][y] = true;
                    dfs(xx,yy);
                    vis[x][y] = vis[x + 1][y] = false;
                }
            }
            if (cs == 2) {
                if (y + 1 < 4 && !vis[x][y] && !vis[x][y + 1]) {
                    vis[x][y] = vis[x][y + 1] = true;
                    dfs(xx, yy);
                    vis[x][y] = vis[x][y + 1] = false;
                }
            }
            if (cs == 3) {
                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, 0, sizeof(vis)); cc = 0; ans = 0;
        cin >> n;
        dfs(0, 0);
    cout << ans<<endl;
    }
    return 0;
}