Hdu2067-rabbit Board

Source: Internet
Author: User

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;}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.