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 }

 

转载于:https://www.cnblogs.com/xingkongyihao/p/7819394.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值