码迷,mamicode.com
首页 > 其他好文 > 详细

D - Almost Identity Permutations /* Codeforces Round 888 D */

时间:2017-11-18 22:03:11      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:ever   script   int   long   分享   for   rom   ber   count   

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 }
View Code

 

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!