[Noi] Move route

Source: Internet
Author: User

Total time limit: 1000ms memory limit: 65536kB
Description
x table has a M row n column of the grid matrix, each square with coordinates, row coordinates from bottom to top, increment, column coordinates from left to right, the coordinates of the lower left Square is (m,n), then the upper right square coordinates are ().
Xiao Ming is a naughty boy, one day he caught an ant, accidentally hurt the right foot of the ant, so ants can only move up or to the right. Xiao Ming put the ant in the lower left corner of the square, the ants from
in the lower left corner, move to the upper-right corner of the grid, moving a square each step. Ants always move within the grid matrix, please calculate the number of different moving routes.
for a grid of 1 rows and 1 columns, the ant moves in situ, the number of moving routes is 1, and for a grid of 1 rows, 2 columns (or 2 rows, 1 columns), the ant only has to move right (or up) one time, and the number of moving routes is 1 ... For a 2-row, 3-column grid matrix, as shown:

-------------------
| (2,1) | (2,2) | (2,3) |
-------------------
| (a) | (from) | (1,3) |
-------------------

There are 3 types of mobile routes for ants:
Route 1: ( a) → (1,3) → (2,3)
Route 2: ( a) → (2,2) → (2,3)
Route 3: (a) → (2,1) → (2,2) → (2,3)
input
Enter only one row, including two integers m and n (0<m+n<=20), representing the number of rows and columns of the grid matrix, separated by spaces between M and N
Output
The
output is only one row, which is the number of different moving routes.
Sample Input
2 3
Sample Output
3

Gster The Great God has spoken the number of routes is C ((M + N), (m) * (n)), where m, n is the number of sides (not points) in the horizontal and vertical directions, respectively. Pay attention to a case where the bottom number is 1.
Code
#include <stdio.h>Long Longjie[ A ];intMain () {intm, N; scanf ("%d%d", &m, &N); if(M = =1|| n = =1) {printf ("1\n"); return 0; } jie[1] =1; jie[2] =2;  for(inti =3; I <= -; i++) {jie[i]= jie[I-1] *i; } printf ("%lld\n", jie[m + N-2]/jie[M-1]/jie[N-1 ]); return 0;}

[Noi] Move route

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.