yukicoder-243

从 Trac 迁移的文章

这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。

原文章内容如下:

{{{
#!html
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
<script type="text/javascript" async src="http://10.71.10.90/sfiction/tool/MathJax/MathJax-master/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
.input, pre {
    display: block;
    padding: 9.5px;
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.42857143;
    color: #333;
    word-break: break-all;
    word-wrap: break-word;
    background-color: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
}
</style>
}}}

== [https://yukicoder.me/problems/no/243 No.243 出席番号(2)] ==

=== Description ===

{{{
#!html
<p>有$N$个数,第$i$个数是$A_i$。问有多少$\{0,1,\dots,N-1\}$的排列$p$,使得对于任意$i$都有$A_i \ne p_i$。输出方案数$\bmod (10^9 + 7)$。</p>
}}}

=== Input ===

{{{
#!html
<p class="input">
$N$<br>
$A_0$<br>
$A_1$<br>
$\vdots$<br>
$A_{N-1}$
</p>
<p>
$1 \le N \le 5000, 0 \le A_i \le 4999$。
</p>
}}}

=== Output ===

{{{
#!html
<p>输出方案数$\bmod (10^9+7)$。</p>
}}}

=== Sample ===

==== Sample 1 ====
输入
{{{
#!html
<pre>
3
0
1
2
</pre>
}}}
输出
{{{
#!html
<pre>
2
</pre>
}}}

==== Sample 2 ====
输入
{{{
#!html
<pre>
4
3
3
3
3
</pre>
}}}
输出
{{{
#!html
<pre>
0
</pre>
}}}

==== Sample 3 ====
输入
{{{
#!html
<pre>
5
1
1
1
0
1
</pre>
}}}
输出
{{{
#!html
<pre>
24
</pre>
}}}

No.243 出席番号(2)

Description

有$N$个数,第$i$个数是$A_i$。问有多少$\{0,1,\dots,N-1\}$的排列$p$,使得对于任意$i$都有$A_i \ne p_i$。输出方案数$\bmod (10^9 + 7)$。

Input

$N$
$A_0$
$A_1$
$\vdots$
$A_{N-1}$

$1 \le N \le 5000, 0 \le A_i \le 4999$。

Output

输出方案数$\bmod (10^9+7)$。

Sample

Sample 1

输入

3012

输出

2
Sample 2

输入

43333

输出

0
Sample 3

输入

511101

输出

24