一开始没过 因为存在某个点的价值是0 数组又开不到-1 所以给价值整体加一 这样就不会出现娶不到的情况
C++ 代码
#include<cstdio>
#include<iostream>
#include<cstring>
#define ll long long
ll mod=1e9+7;
const int N =51;
ll dp[N][N][25][25];
int arr[N][N];
int n,m,k;
using namespace std;
void solve(int i,int j,int num,int val)
{
if(dp[i][j][num][val]!=-1)
return ;
dp[i][j][num][val]=0;
if(i==n&&j==m&&num==k)
{
dp[i][j][num][val]=1;
return ;
}
if(arr[i][j]>val&&num<k)
{
solve(i,j,num+1,arr[i][j]);
dp[i][j][num][val]+=dp[i][j][num+1][arr[i][j]];
dp[i][j][num][val]%=mod;
}
if(i<n)
{
solve(i+1,j,num,val);
dp[i][j][num][val]+=dp[i+1][j][num][val];
dp[i][j][num][val]%=mod;
}
if(j<m)
{
solve(i,j+1,num,val);
dp[i][j][num][val]+=dp[i][j+1][num][val];
dp[i][j][num][val]%=mod;
}
}
int main()
{
memset(dp,-1,sizeof dp);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>arr[i][j];
arr[i][j]++;
}
solve(1,1,0,0);
cout<<dp[1][1][0][0]%mod;
}