HDU2067 Little Bunny's chess board

Source: Internet
Author: User

Description

The rabbit's uncle from the travel back to bring her a gift, the little rabbit happy to run back to his room, opened a look is a chessboard, little rabbit disappointed. But not a few days found the board of fun. The shortest path from the starting point (0,0) to the end point (N,n) is C (2n,n), and now the rabbit wants to do so if it does not cross the diagonal (but can touch the grid point on the diagonal), how many paths are there? The rabbit thought for a long time did not think out, now want to ask you to help the rabbit to solve this problem, for you should not be difficult !

Input

Enter a number n (1<=n<=35) at a time, when n equals-1 o'clock ends the input.

Output

For each input data output path number, the specific format looks at sample.

Sample Input

1 3 12-1

Sample Output

1 1 2 2 3 10 3 12 416024

Simple dynamic planning, very suitable for the introduction ah, before the dynamic planning, did not expect to encounter in the training game.

This should be a demarcation, from the theory of learning to water problem suddenly think of a very funny metaphor, the difficulty of the algorithm is a woman's clothes, a man's ideas are in this dress, but want is not this dress.

The difficulty of the algorithm to a certain extent is the reason I like, haha, really sarcastic ah.

1#include <iostream>2#include <stdio.h>3#include <string.h>4 using namespacestd;5 Long Longdp[ +][ +];6 intMain ()7 {8     intN;9     intt=1;Ten      for(intI=1; i<= $; i++) Onedp[i][0]=1; A      for(intI=1;i< $; i++) -     { -          for(intj=1;j< $; j + +) the         { -             if(I==J) dp[i][j]=dp[i][j-1]; -             Else -dp[i][j]=dp[i-1][j]+dp[i][j-1]; +         } -     } +      while(cin>>n&&n!=-1) A     { atcout<<t++<<" "<<n<<" "; -cout<<2*dp[n][n]<<Endl; -     } -}

A brief introduction to this question:

Because the shortest path is required, so repeated walking is not possible, so the side of the lattice can only have a path (no matter how far from the starting point), this condition can be known, there is the processing of the diagonal, the problem requires not to cross the diagonal,

Let's think about what is called passing through a grid, putting a number of paths to a grid and even passing through the grid, and now we can handle it well without going through the diagonal, we just have to do without the number of paths through the diagonal. One more thing to say is that as it goes down, 1. The number of paths in the upper triangle does not add up to the next triangle, 2. The end point is on the diagonal, which results in the calculation of only half the number of paths, why half, or diagonal division is the upper and lower path number symmetry. It's worth saying, it's like this, it's a water problem anyway.

HDU2067 Little Bunny's chess board

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.