数据量很小 直接爆搜就可以
(55)4^5
正常读入数据,之后dfs
用哈希表存 unordered_set<>
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int w[6][6];
int ans = 0;
unordered_set<int> S;
int X[4] = {1,-1,0,0};
int Y[4] = {0,0,1,-1};
void dfs(int x,int y , int tk,int str){
if(tk>=k){
if(!S.count(str)){
//cout<<"x = "<<x<<": y = "<<y<<": tk = "<<tk<<": str = "<<str<<endl;
ans++;
S.insert(str);
}
return;
}
for(int i = 0; i < 4; i ++ ){
int xx = X[i]+x;
int yy = Y[i]+y;
if(xx>=1 && yy>=1 && xx<= n && yy<= m)dfs(xx,yy,tk+1,str*10+w[xx][yy]);
}
return;
}
int main()
{
cin>>n>>m>>k;
for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
scanf("%d",&w[i][j]);
for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
{
dfs(i,j,0,w[i][j]);
}
cout<<ans<<endl;
return 0;
}