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

走方格的方案数

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

排列组合,我们知道它随便怎么走都是m+n步那我们m+n里挑m步进行选择就是C(m)/(m+n),不知道怎么输出排列组合,,ԾㅂԾ,,

#include <algorithm>

using namespace std;

int permutation(const int n,const int m){
    //求C(n)/(m+n)或C(m)/(m+n)
    int temp=1;
    for(int i=m+n;i>n;i--){
        temp*=i;
    }
    int mfac=1;
    for(int j=m;j>0;j--){
        mfac*=j;
    }
    return temp/mfac;
}

int main() {
    int n,m;
    while(cin>>n>>m){
        int cnt = 0;
        cnt = permutation(n,m);
        cout<<cnt<<endl;
        
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务