Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- long long binom(long long n, long long k) {
- if(n < k) {
- swap(n, k);
- }
- long long a = 1;
- for(long long i = 1; i <= n; i++) {
- a *= i;
- }
- long long b = 1;
- for(long long i = 1; i <= k; i++) {
- b *= i;
- }
- long long c = 1;
- for(long long i = 1; i <= (n - k); i++) {
- c *= i;
- }
- return a / (b * c);
- }
- int main()
- {
- long long a,n,m,k;
- cin>>a>>n>>m>>k;
- long long ans=0;
- for(long long i = 0; i <= n; i++) {
- for(long long j = 0; j <= m; j++) {
- for(long long p = 0; p <= k; p++) {
- if(i >= p and j >= p and i + j - p <= a) {
- ans += binom(a, p) * binom(a - p, i - p) * binom(a - i, j - p);
- }
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement