Educational Codeforces Round 3 D

D. Almost Identity Permutations

A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.

Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i.

Your task is to count the number of almost identity permutations for given numbers n and k.

Input

The first line contains two integers n and k (4 ≤ n ≤ 1000, 1 ≤ k ≤ 4).

Output

Print the number of almost identity permutations for given n and k.

Examples
Input
4 1
Output
1
Input
4 2
Output
7
Input
5 3
Output
31
Input
5 4
Output
76
 由于k只有4个数 所以在纸上算就不难算出
k == 1时  答案为1
k == 2时  答案为1+C(2,n)*1
k == 3时  答案为1+C(2,n)*1+C(3,n)*2
k == 4时 答案为1+C(2,n)*1+C(3,n)*2+C(4,n)*9
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 int main() {
 5     ll n, k;
 6     cin >> n >> k;
 7     if(k == 1) printf("1\n");
 8     else if(k == 2) printf("%lld\n",1+n*(n-1)/2);
 9     else if(k == 3) printf("%lld\n",1+n*(n-1)/2+n*(n-1)*(n-2)/3);
10     else if(k == 4) printf("%lld\n",1+n*(n-1)/2+n*(n-1)*(n-2)/3+n*(n-1)*(n-2)*(n-3)*3/8);
11     return 0;
12 }

 

posted @ 2017-11-11 16:45  starry_sky  阅读(229)  评论(0编辑  收藏  举报