solution.cpp 524 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <bits/stdc++.h>
using namespace std;

int a[4][5];
int sum;
void dfs(int row, int col, int index)
{
    if (a[row][col] == index && index == 7)
        sum++;
    else
    {
        if (row + 1 < 4)
            dfs(row + 1, col, index + 1);
        if (col + 1 < 5)
            dfs(row, col + 1, index + 1);
    }
}
int main()
{
    int row, col;
    for (row = 0; row < 4; row++)
        for (col = 0; col < 5; col++)
            a[row][col] = row + col;

    dfs(0, 0, 0);
    cout << sum << endl;
    return 0;
}