D. Almost Identity Permutations
Description
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
题意:
就是有一个集合里面是1~n个元素,但是这些元素的排列是随机的。问最多有多少个这样的排列,使得至少有n-k个 pi=i。
代码:(????)
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 ////先交一发别人的代码回头研究 = = 这个规律很膨胀啊 !!! 6 long long n,k,ar=1; 7 cin>>n>>k; 8 if(k>=2) ar+=n*(n-1)/2; 9 if(k>=3) ar+=n*(n-1)*(n-2)/3; 10 if(k>=4) ar+=n*(n-1)*(n-2)*(n-3)*3/8; 11 cout<<ar; 12 return 0; 13 }