zoukankan      html  css  js  c++  java
  • Permutation Descent Counts(递推)

    1968: Permutation Descent Counts

            Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 123     Solved: 96    


    Description

    Given a positive integer, N, a permutation of order N is a one-to-one (and thus onto) function from the set of integers from 1 to N to itself. If p is such a function, we represent the function by a list of its values: [ p(1) p(2) … p(N) ]

    For example,
    [5 6 2 4 7 1 3] represents the function from { 1 … 7 } to itself which takes 1 to 5, 2 to 6, … , 7 to 3.
    For any permutation p, a descent of p is an integer k for which p(k) > p(k+1). For example, the permutation [5 6 2 4 7 1 3] has a descent at 2 (6 > 2) and 5 (7 > 1).
    For permutation p, des(p) is the number of descents in p. For example, des([5 6 2 4 7 1 3]) = 2. The identity permutation is the only permutation with des(p) = 0. The reversing permutation with p(k) = N+1-k is the only permutation with des(p) = N-1 .

    The permutation descent count (PDC) for given order N and value v is the number of permutations p of order N with des(p) = v. For example:

    PDC(3, 0) = 1 { [ 1 2 3 ] }
    PDC(3, 1) = 4 { [ 1 3 2 ], [ 2 1 3 ], [ 2 3 1 ], 3 1 2 ] }
    PDC(3, 2) = 1 { [ 3 2 1 ] }`

    Write a program to compute the PDC for inputs N and v. To avoid having to deal with very large numbers, your answer (and your intermediate calculations) will be computed modulo 1001113.

    Input

    The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set should be processed identically and independently.

    Each data set consists of a single line of input. It contains the data set number, K, followed by the integer order, N (2 ≤ N ≤ 100), followed by an integer value, v (0 ≤ v ≤ N-1).

    Output

    For each data set there is a single line of output. The single output line consists of the data set number, K, followed by a single space followed by the PDC of N and v modulo 1001113 as a decimal integer.

    Sample Input

    4
    1 3 1
    2 5 2
    3 8 3
    4 99 50

    Sample Output

    1 4
    2 66
    3 15619
    4 325091

    Hint

    Source

    2017湖南多校第十三场

    //题意:给出 n,v 求 1 -- n 的排列中,相邻的数,出现 v 次前面数比后面数大的种数。

    题解:假如设 dp[i][j] 为 1 -- i 的排列,出现 j 次前面数比后面数大的情况的种数,那么

    递推,有两个来源,dp[i-1][j] 和 dp[i-1][j-1] ,只要考虑 i 放置的位置即可,分清楚情况讨论清楚即可!

    比赛时没想清楚唉!

     1 # include <cstdio>
     2 # include <cstring>
     3 # include <cstdlib>
     4 # include <iostream>
     5 # include <vector>
     6 # include <queue>
     7 # include <stack>
     8 # include <map>
     9 # include <bitset>
    10 # include <set>
    11 # include <cmath>
    12 # include <algorithm>
    13 using namespace std;
    14 #define lowbit(x) ((x)&(-x))
    15 #define pi acos(-1.0)
    16 #define eps 1e-8
    17 #define MOD 1001113
    18 #define INF 0x3f3f3f3f
    19 #define LL long long
    20 inline int scan() {
    21     int x=0,f=1; char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    24     return x*f;
    25 }
    26 inline void Out(int a) {
    27     if(a<0) {putchar('-'); a=-a;}
    28     if(a>=10) Out(a/10);
    29     putchar(a%10+'0');
    30 }
    31 #define MX 105
    32 //Code begin...
    33 int dp[MX][MX];
    34 
    35 void Init()
    36 {
    37     dp[1][0]=1;
    38     for (int i=2;i<=100;i++)
    39     {
    40         for (int j=0;j<=i-1;j++)
    41         {
    42             dp[i][j] = dp[i-1][j]*(j+1)%MOD;
    43             if (j!=0)
    44                 dp[i][j] = (dp[i][j]+dp[i-1][j-1]*(i-j))%MOD;
    45         }
    46     }
    47 }
    48 
    49 int main()
    50 {
    51     Init();
    52     int t = scan();
    53     while (t--)
    54     {
    55         int c = scan();
    56         int n = scan();
    57         int m = scan();
    58         printf("%d %d
    ",c,dp[n][m]);
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    mysql 聚集函数 count 使用详解
    在Docker中使用kettle遇到的问题解决
    整取零存_字段级迁移工具
    快速修改MySQL字段类型
    数据仓库知识点梳理(4)
    五一节分享60多本免费AI电子书
    数据仓库知识点梳理(3)
    数据仓库知识点梳理(2)
    数据仓库知识点梳理(1)
    解决MacVim在macOS Catalina下字母显示不全的问题
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/7345523.html
Copyright © 2011-2022 走看看