华为笔试题之一,求n和m的组合数
#include <iostream>
using namespace std;
int FC(int X, int Y)
{
int count=1;
if(Y == 0 || Y == X)
return 1;
for(int i=0; i<Y; ++i)
{
count *= X - i;
count /= i + 1;
}
return count;
}
int main() {
int n, m;
cin >> n >> m;
int res=0;
if(n==m)
{
for(int i=0; i< n-1; ++i)
{
int x = n * FC(n-1, i);
res += x;
}
res = res +1;
}
if(n < m)
{
for(int i=0; i<= n-1; ++i)
{
int x = n * FC(n - 1, i);
res += x;
}
}
if( n > m)
{
for(int i=0; i<= m-2; ++i)
{
int x = n * FC(n - 1, i);
res += x;
}
res = res + FC(n, m);
}
cout << res << endl;
return 0;
} #华为##笔试题目#