Codeforces Round 233 (Div. 1)
E
Sorting Permutations
Codeforces
未评级
原题
← D→
翻译中…

We are given a permutation sequence $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ of numbers from $1$ to $*n*$. Let's assume that in one second, we can choose some disjoint pairs $(*u*_{1}, *v*_{1}), (*u*_{2}, *v*_{2}), ..., (*u*_{*k*}, *v*_{*k*})$ and swap all $*a*_{*u*_{*i*}}$ and $*a*_{*v*_{*i*}}$ for every $*i*$ at the same time ($1 ≤ *u*_{*i*} < *v*_{*i*} ≤ *n*$). The pairs are disjoint if every $*u*_{*i*}$ and $*v*_{*j*}$ are different from each other.

翻译中…

We want to sort the sequence completely in increasing order as fast as possible. Given the initial permutation, calculate the number of ways to achieve this. Two ways are different if and only if there is a time $*t*$, such that the set of pairs used for swapping at that time are different as sets (so ordering of pairs doesn't matter). If the given permutation is already sorted, it takes no time to sort, so the number of ways to sort it is $1$.

翻译中…

To make the problem more interesting, we have $*k*$ holes inside the permutation. So exactly $*k*$ numbers of $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ are not yet determined. For every possibility of filling the holes, calculate the number of ways, and print the total sum of these values modulo $1000000007$ $(10^{9} + 7)$.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ $(1 ≤ *n* ≤ 10^{5})$ and $*k*$ $(0 ≤ *k* ≤ 12)$. The second line contains the permutation sequence $*a*_{1}, ..., *a*_{*n*}$ $(0 ≤ *a*_{*i*} ≤ *n*)$. If a number is not yet determined, it is denoted as $0$. There are exactly $*k*$ zeroes. All the numbers $*a*_{*i*}$ that aren't equal to zero are distinct.

翻译中…

Output

翻译中…

Print the total sum of the number of ways modulo $1000000007$ $(10^{9} + 7)$.

翻译中…

样例

Input #1
5 0
1 5 2 4 3
Output #1
6
InputCopy OutputCopy
Input #2
5 2
1 0 2 4 0
Output #2
7
InputCopy OutputCopy
题目信息
题号
398E
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。