zoukankan      html  css  js  c++  java
  • 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
    ");
     8     else if(k == 2) printf("%lld
    ",1+n*(n-1)/2);
     9     else if(k == 3) printf("%lld
    ",1+n*(n-1)/2+n*(n-1)*(n-2)/3);
    10     else if(k == 4) printf("%lld
    ",1+n*(n-1)/2+n*(n-1)*(n-2)/3+n*(n-1)*(n-2)*(n-3)*3/8);
    11     return 0;
    12 }
  • 相关阅读:
    【2021-04-15】台上一分钟,背后十年功
    【2021-04-14】买了人生中的第一个车位
    计算机网络实验部分
    乘积最大子数组
    计算各个位数不同的数字个数
    周总结
    最长回文子序列
    最长回文串
    回文子串
    拼图
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7819394.html
Copyright © 2011-2022 走看看