题解 | #走方格的方案数#

走方格的方案数

http://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b

直接排列组合,不管怎么走,总要从左上到右下,那么要向下走nnn次,向右走mmm次,总共也只走m+n次,那么方法数就是从这m+n次中选出mmm次向右走的方案,即C(m+n)(m)(用n也一样)那么最终方案数就是:

#include<iostream>
using namespace std;
int main(void)
{
    int m,n;
    while(cin>>m>>n)
    {
        long long down = 1;
        long long up = 1;
        
        for(int i = m+n;i>m;i--)up = up* i;
        for(int i = n;i>=1;i--)down = down * i;
        
        long long res = up / down;
        cout<<res<<endl;
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
牛客383479252号:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务