踩方格

踩方格

时间限制: 1000 ms 内存限制: 65536 KB

【题目描述】

有一个方格矩阵,矩阵边界在无穷远处。我们做如下假设:

  1. 每走一步时,只能从当前方格移动一格,走到某个相邻的方格上;
  2. 走过的格子立即塌陷无法再走第二次;
  3. 只能向北、东、西三个方向走;

请问:如果允许在方格矩阵上走 n n n 步,共有多少种不同的方案。 2 2 2 种走法只要有一步不一样,即被认为是不同的方案。

【输入】

允许在方格上行走的步数 n ( n ≤ 20 ) n(n≤20) n(n20)

【输出】

计算出的方案数量。

【输入样例】

2

【输出样例】

7
/***  Amber  ***/
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
//#include <unordered_map>
#include <vector>
using namespace std;
#define ls (rt<<1)
#define rs (rt<<1|1)
typedef long long ll;
template <typename T>
inline void read(T &x) {
    x = 0;
    static int p;
    p = 1;
    static char c;
    c = getchar();
    while (!isdigit(c)) {
        if (c == '-')p = -1;
        c = getchar();
    }
    while (isdigit(c)) {
        x = (x << 1) + (x << 3) + (c - 48);
        c = getchar();
    }
    x *= p;
}
template <typename T>
inline void print(T x) {
    if (x<0) {
        x = -x;
        putchar('-');
    }
    static int cnt;
    static int a[50];
    cnt = 0;
    do {
        a[++cnt] = x % 10;
        x /= 10;
    } while (x);
    for (int i = cnt; i >= 1; i--)putchar(a[i] + '0');
    puts("");
}
const double Pi=acos(-1);
const double eps=1e-6;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e5+10;
ll n;
bool vis[110][110];
ll dfs(int x,int y,int n) {
    if (!n) return 1;
    int res = 0;
    vis[x][y] = 1;
    if (!vis[x - 1][y]) res += dfs(x - 1, y, n - 1);
    if (!vis[x][y - 1]) res += dfs(x, y - 1, n - 1);
    if (!vis[x][y + 1]) res += dfs(x, y + 1, n - 1);
    vis[x][y] = 0;
    return res;
}
inline void work() {
    read(n);
    print(dfs(25, 25, n));
}
int main() {
    //freopen("1.txt","r",stdin);
    int T = 1;
    //read(T);
    while (T--) {
        work();
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值