Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2067
, The matrix is symmetric with Y =-X, that is, x = Y. Therefore, you only need to calculate the half of the matrix, and then multiply by two. All the data in the first row can only be transmitted from the left, therefore, DP [0] [J] = 1;
Other paths can be passed over to the left. Therefore, DP [I] [J] = DP [I-1] [J] + dp [I] [J-1];
However, note that when I = J, because only half of the graph is used, special consideration is required. Therefore, when I = J, it can only be passed over, therefore, when I = J, DP [I] [J] = DP [I-1] [J];
#include "stdio.h"#include "string.h"#include "stdlib.h"#include "math.h"#include "algorithm"#include "iostream"using namespace std;#define maxn 10005 long long dp[ maxn ][ maxn ]; int main(){int i , j , n ;for( i = 1 ; i <= 35 ; i++ )dp[ 0 ][ i ] = 1 ;for( i = 1 ; i <= 35 ; i++ ){for( j = 1 ; j <= 35 ; j++ ){if( j == i ) dp[ i ][ j ] = dp[ i - 1 ][ j ] ;elsedp[ i ][ j ] = dp[ i - 1 ][ j ] + dp[ i ][ j - 1 ] ;}}int Case = 0 ;while( ~scanf( "%d" , &n ) ){if( n == -1 )break;printf( "%d %d %I64d\n" , ++Case , n , dp[ n ][ n ] * 2 ) ;} return 0;}