赞
踩
14
package com.lulu.main9;
import java.util.Scanner;
public class Main {
static int n, m, k;//程序输入值
//为记忆化搜索做标记,避免重复,已经知道有多少种方法就不用在计算了
static int [][][][] plan = new int [51][51][13][13];
static int [][] map;//所要走的地图
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
k = in.nextInt();
map = new int[n][m];
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
map[i][j] = in.nextInt();
}
}
for(int a = 0; a < 51; a++)
{
for(int b = 0; b < 51; b++)
{
for(int c = 0; c < 13; c++)
{
for(int d = 0; d < 13; d++)
{
plan[a][b][c][d] = -1;
}
}
}
}
plan[0][0][0][0] = bfs(0,0,0,-1);
System.out.println(plan[0][0][0][0]);
}
private static int bfs(int i, int j, int count, int max) {
if(plan[i][j][count][max+1]!=-1)
{
return plan[i][j][count][max+1];
}
int t = 0;
if(i == n-1 && j == m-1)
{
if(count == k || (count == k-1 && max < map[i][j])) t++;
return plan[i][j][count][max+1] = t;
}
if(i + 1 < n)
{
if(max < map[i][j])
t += bfs(i+1,j,count+1,map[i][j]);
t += bfs(i+1, j, count, max);
}
if(j + 1 < m)
{
if(max < map[i][j])
t += bfs(i, j+1, count+1, map[i][j]);
t += bfs(i, j+1, count, max);
}
t %= 1000000007;
return plan[i][j][count][max+1] = t;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。