• D


    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
    まだまだだね
  • 相关阅读:
    4.一对多关联映射
    3.一对一关联映射
    1.Hibernate框架
    19。数据库技术及分页
    18.文件的上传和下载
    17.JavaMail
    16.部署描述符文件
    15.Servlet程序结构与部署
    dba-查询sql耗时
    (72)C# 特性
  • 原文地址:https://www.cnblogs.com/xxQ-1999/p/7857817.html
Copyright © 2020-2023  润新知