标签:des style blog http color io os ar java

1 6 6 4 5 6 6 4 3 2 2 3 1 7 2 1 1 4 6 2 7 5 8 4 3 9 5 7 6 6 2 1 5 3 1 1 3 7 2
3948
记忆化搜索,逆推着算,可以用到之前推出的结果。
opt[i][j] 计算从ij点到最后的方法
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[2][2] = { {1,0},{0,1} };
int opt[120][120] , Map[120][120] , n , m ;
void dp(int x,int y,int k)
{
int i , j ;
for(i = x ; i < n && i <= x+k ; i++)
{
for(j = y ; j < m && j <= y + ( k-(i-x) ) ; j++)
{
if( i == x && j == y ) continue ;
opt[x][y] = ( opt[x][y] + opt[i][j] ) % 10000 ;
}
}
}
int main()
{
int t , i , j ;
scanf("%d", &t);
while(t--)
{
scanf("%d %d", &n, &m);
for(i = 0 ; i < n ; i++)
for(j = 0 ; j < m ; j++)
scanf("%d", &Map[i][j]);
memset(opt,0,sizeof(opt));
opt[n-1][m-1] = 1 ;
for(i = n-1 ; i >= 0 ; i--)
for(j = m-1 ; j >= 0 ; j--)
{
if( i == n-1 && j == m-1 ) continue ;
dp(i,j,Map[i][j]);
}
printf("%d\n", opt[0][0]);
}
return 0;
}
标签:des style blog http color io os ar java
原文地址:http://blog.csdn.net/winddreams/article/details/40373533