CF340E.Iahub and Permutations

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.

The girl finds an important permutation for the research. The permutation contains n distinct integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ n). She replaces some of permutation elements with -1 value as a revenge.

When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element a__k which has value equal to k (a__k = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7).

伊阿胡布发明了冒泡排序图,兴奋不已,整天待在办公室里写排列。伊阿胡比娜生气地发现,自己对伊阿胡布而言已不再重要。当伊阿胡布离开后,伊阿胡比娜来到他的办公室,蓄意破坏他的研究工作。

这位姑娘找到了一个对研究至关重要的排列。该排列包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \dots, a_n(其中 1≤ai≤n1 \leq a_i \leq n)。作为报复,她将排列中某些元素替换为 −1-1。

当伊阿胡布发现他那重要的排列已被破坏时,他试图将其恢复。但他唯一还记得的是:原始排列中不存在不动点。所谓排列的不动点,是指某个元素 aka_k 满足其值等于其下标 kk(即 ak=ka_k = k)。你的任务是向伊阿胡布证明:尝试恢复该排列并非良策。请输出所有可能的原始重要排列的数目(即满足条件的排列总数),结果对 10000000071000000007(即 109+710^9 + 7)取模。

输入格式

The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.

It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation.

第一行包含一个整数 nn(2≤n≤20002 \leq n \leq 2000)。第二行包含 nn 个整数,表示 Iahubina 将 Iahub 的一个重要排列中某些值替换为 −1-1 后得到的序列。

保证给定排列中不存在不动点。此外,给定序列中至少包含两个 −1-1,且每个正数在序列中至多出现一次。保证至少存在一个满足条件的排列。

输出格式

Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7).

输出一个整数,表示 Iahub 恢复其排列的方法数,对 10000000071000000007(即 109+710^9 + 7)取模。

输入输出样例

  • 输入#1

    5
    -1 -1 4 3 -1

    输出#1

    2

说明/提示

For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point.

对于第一个测试样例,不存在不动点的排列有两个:[2, 5, 4, 3, 1] 和 [5, 1, 4, 3, 2]。其余任意排列至少存在一个不动点。

输入解题思路,AI测评打分。不知道怎么写?

首页