#include <string>
#include <iostream>
using namespace std;
int countpath(int mat[][3],int m,int n,int k)
{
if(m<0||n<0)return 0;
if(m==0&&n==0)
{
return (k==mat[0][0]);
}
else
{
return countpath(mat,m-1,n,k-mat[m][n])+countpath(mat,m,n-1,k-mat[m][n]);
}
}
int main()
{
int mat[3][3] = { {1, 2, 3},
{4, 6, 5},
{3, 2, 1}
};
int k=12;
cout<<countpath(mat,2,2,k);
}
#include <iostream>
using namespace std;
int countpath(int mat[][3],int m,int n,int k)
{
if(m<0||n<0)return 0;
if(m==0&&n==0)
{
return (k==mat[0][0]);
}
else
{
return countpath(mat,m-1,n,k-mat[m][n])+countpath(mat,m,n-1,k-mat[m][n]);
}
}
int main()
{
int mat[3][3] = { {1, 2, 3},
{4, 6, 5},
{3, 2, 1}
};
int k=12;
cout<<countpath(mat,2,2,k);
}
No comments:
Post a Comment