标签:ever script int long 分享 for rom ber count
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.
The first line contains two integers n and k (4?≤?n?≤?1000, 1?≤?k?≤?4).
Print the number of almost identity permutations for given n and k.
4 1
1
4 2
7
5 3
31
5 4
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 }
D - Almost Identity Permutations /* Codeforces Round 888 D */
标签:ever script int long 分享 for rom ber count
原文地址:http://www.cnblogs.com/xxQ-1999/p/7857817.html