zoukankan      html  css  js  c++  java
  • 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
    まだまだだね
  • 相关阅读:
    DLink无线路由器做交换机配置
    解决超过两小时的问题记录
    SIP学习之旅【资料收集篇】

    从google code里面获取代码的方法
    NSString表示的时间转为time_t
    C语言中 时间日期格式化符号 详解
    (转)time_t的定义
    (分享)简单圆角UITextView
    viewDidUnload释疑
  • 原文地址:https://www.cnblogs.com/xxQ-1999/p/7857817.html
Copyright © 2011-2022 走看看