1968: Permutation Descent Counts

Submit Page   Summary   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 放置的位置即可,分清楚情况讨论清楚即可!

比赛时没想清楚唉!

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define pi acos(-1.0)
#define eps 1e-8
#define MOD 1001113
#define INF 0x3f3f3f3f
#define LL long long
inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 105
//Code begin...
int dp[MX][MX]; void Init()
{
dp[][]=;
for (int i=;i<=;i++)
{
for (int j=;j<=i-;j++)
{
dp[i][j] = dp[i-][j]*(j+)%MOD;
if (j!=)
dp[i][j] = (dp[i][j]+dp[i-][j-]*(i-j))%MOD;
}
}
} int main()
{
Init();
int t = scan();
while (t--)
{
int c = scan();
int n = scan();
int m = scan();
printf("%d %d\n",c,dp[n][m]);
}
return ;
}

Permutation Descent Counts(递推)的更多相关文章

  1. permutation 2(递推 + 思维)

    permutation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  2. CSU 1968 Permutation Descent Counts

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1968 题意:对于任一种N的排列A,定义它的E值为序列中满足A[i]>A[i+1]的数的个 ...

  3. 【HDOJ6630】permutation 2(递推)

    题意:给定x,y,n,有标号从1到n的n个数组,求合法的排列个数模998244353使得 1:p[1]=x 2:p[n]=y 3:相邻两项的差的绝对值<=2 n<=1e5 思路: #inc ...

  4. Codeforces Gym10081 A.Arcade Game-康托展开、全排列、组合数变成递推的思想

    最近做到好多概率,组合数,全排列的题目,本咸鱼不会啊,我概率论都挂科了... 这个题学到了一个康托展开,有点用,瞎写一下... 康托展开: 适用对象:没有重复元素的全排列. 把一个整数X展开成如下形式 ...

  5. 四角递推(CF Working out,动态规划递推)

    题目:假如有A,B两个人,在一个m*n的矩阵,然后A在(1,1),B在(m,1),A要走到(m,n),B要走到(1,n),两人走的过程中可以捡起格子上的数字,而且两人速度不一样,可以同时到一个点(哪怕 ...

  6. UVA 11077 Find the Permutations 递推置换

                               Find the Permutations Sorting is one of the most used operations in real ...

  7. Code Force 429B Working out【递推dp】

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  8. 【BZOJ-2476】战场的数目 矩阵乘法 + 递推

    2476: 战场的数目 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 58  Solved: 38[Submit][Status][Discuss] D ...

  9. 从一道NOI练习题说递推和递归

    一.递推: 所谓递推,简单理解就是推导数列的通项公式.先举一个简单的例子(另一个NOI练习题,但不是这次要解的问题): 楼梯有n(100 > n > 0)阶台阶,上楼时可以一步上1阶,也可 ...

随机推荐

  1. 微信小程序 - 表单验证插件WxValidate(自定义警告信息形式)

    弹出的形式对于用户来说,总是不太友好的 可能会出现层级问题(只需要设置一下提示的层级即可) WxValidate内置规则 以下代码拷贝即可使用~ wxml <form bindsubmit='s ...

  2. 【MyBatis学习14】MyBatis和Spring整合

    前面十几篇博文总结了mybatis在开发中的相关技术,但在实际中都是和spring整合开发的,所以这里总结一下mybatis和spring的整合方法,并在整合后进行测试. 1. 整合的环境 这都是老掉 ...

  3. Android学习笔记(一)——Activity简介 和 View

    源文链接:http://www.cnblogs.com/shyang--TechBlogs/archive/2011/03/14/1984195.html Android SDK ( Software ...

  4. 虚拟机实现https网络设置

    现在很多网站使用的都是https协议,想在自己的电脑上实现下, 由于自己的电脑是win10,我总是觉得在windows上布置环境不如在linux上稳定,所以在电脑上安装了虚拟机,cento系统 . 上 ...

  5. Spark调研笔记第6篇 - Spark编程实战FAQ

    本文主要记录我使用Spark以来遇到的一些典型问题及其解决的方法,希望对遇到相同问题的同学们有所帮助. 1. Spark环境或配置相关 Q: Sparkclient配置文件spark-defaults ...

  6. vue 结合localStorage 来双向绑定数据

    结合localStorage 来双向绑定数据(超级神奇) localStorage.js: const STORAGE_KEY = 'todos_vuejs' export default { fet ...

  7. 自己动手开发更好用的markdown编辑器-06(自动更新)

    这里文章都是从个人的github博客直接复制过来的,排版可能有点乱. 原始地址 http://benq.im/2015/05/12/hexomd-06/   文章目录 1. 自动更新方案 2. 实现 ...

  8. CentOS7中关闭selinux

    在安装Cobbler和Puppet时需要关闭selinux,但是通常情况下载安装完CentOS7后,默认情况下SElinux是启用状态, 如下所示: [csharp] view plaincopy   ...

  9. c++ 逗号操作符重载

    Overload Operator Comma 首先看看think in c++ 给出的一个重载的样例 #include <iostream> using namespace std; c ...

  10. bwlabel

    bwlabel是用来标记二维的二值图像中的连通组的,简言之,就是黑背景下面有多少白的块,也就是从黑背景甄别白块块的. L = bwlabel(BW, n) returns a matrix L, of ...