王老头

导航

牛客网 网格走法数目

题目描述

有一个X*Y的网格,小团要在此网格上从左上角到右下角,只能走格点且只能向右或向下走。请设计一个算法,计算小团有多少种走法。给定两个正整数int x,int y,请返回小团的走法数目。

输入描述:

输入包括一行,逗号隔开的两个正整数x和y,取值范围[1,10]。

输出描述:

输出包括一行,为走法的数目。
示例1

输入

3 2

输出

10

思路:用组合数学来解。
def fun(num):
    res = 1
    while(num!=1):
        res *= num
        num -= 1
    return res

while True:
    try:
        total = list(map(int,raw_input().split()))
        down = total[0]
        right = total[1]
        print(fun(down+right)//fun(down)//fun(right))
    except Exception as e:
        break

 

posted on 2018-09-06 21:58  王老头  阅读(119)  评论(0)    收藏  举报