递归小白-二维

#include <iostream>
using namespace std;

const int N = 3;
int c[N][N];

int fun00();
int fun01(int);
int fun02(int);
int fun10(int);
int fun11(int);
int fun12(int);
int fun(int, int);
int res = 0;
int main()
{
    for (int i=0; i<N; i++)
    {
        for (int j=0; j<N; j++)
        {
            c[i][j] = 0;
        }
    }
    cout << fun(0, 0) << endl;
    return 0;
}
int fun(int i, int j)
{
    if ((i < N-1) && (j == N))
    {
        i++;
        j = 0;
    }
   if ((i == N-1) && (N-1 == j))
   {
       c[i][j] = 0;
       res++;
       c[i][j] = 1;
       res++;
       c[i][j] = 2;
       res++;
   }
   else
   {
      c[i][j] = 0;
      res = fun(i, j+1);
      c[i][j] = 1;
      res = fun(i, j+1);
      c[i][j] = 2;
      res = fun(i, j+1);
   }
   return res;
}
int fun00()
{
    int res = 0;

        c[0][0] = 0;
        res = fun01(res);
        c[0][0] = 1;
        res = fun01(res);
        c[0][0] = 2;
        res = fun01(res);

    return res;
}
int fun01(int res)
{

        c[0][1] = 0;
        res = fun02(res);
        c[0][1] = 1;
        res = fun02(res);
        c[0][1] = 2;
        res = fun02(res);

    return res;
}
int fun02(int res)
{

        c[0][2] = 0;
        res = fun10(res);
        c[0][2] = 1;
        res = fun10(res);
        c[0][2] = 2;
        res = fun10(res);

    return res;
}
int fun10(int res)
{

        c[1][0] = 0;
        res = fun11(res);
        c[1][0] = 1;
        res = fun11(res);
        c[1][0] = 2;
        res = fun11(res);

    return res;
}
int fun11(int res)
{

        c[1][1] = 0;
        res = fun12(res);
        c[1][1] = 1;
        res = fun12(res);
        c[1][1] = 2;
        res = fun12(res);

    return res;
}
int fun12(int res)
{

        c[1][2] = 0;
        res++;
        c[1][2] = 1;
        res++;
        c[1][2] = 2;
        res++;
    return res;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值