Description
最近LG的RP爆发,准备买注彩票,而他正好找到了一种看起来不错的彩票。
这种彩票需要从1到i中选出j个号码,然后从1到k中选出l个号码。
LG想知道他到底可以有多少种选择号码的方法。
Input
一行四个正整数 i j k l
Output
一行 选择号码的方法数(应该不必涉及高精度)
Sample Input
5 2 7 5
Sample Output
210
Source
Unknown
思路:从m个元素中选n个: c(n, m) = c(n - 1) + c(n, m - 1)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define eps 1e-9
const int inf =
0x3f3f3f3f;
const int mod = 1e9+
7;
const int maxn =
8000 +
8;
int i, j, k, l;
ll fun(int a,
int b)
{
if(a ==
0)
return 1;
if(a == b)
return 1;
return fun(a -
1, b -
1) + fun(a, b -
1);
}
int main()
{
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> i >> j >> k >>
l;
ll sum =
0;
sum =
fun(j, i);
sum *=
fun(l, k);
cout << sum <<
'\n';
return 0;
}
转载于:https://www.cnblogs.com/RootVount/p/11448453.html
相关资源:JAVA上百实例源码以及开源项目