CF288B.Polo the Penguin and Houses
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer p__i (1 ≤ p__i ≤ n).
Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house p__x), then he goes to the house whose number is written on the plaque of house p__x (that is, to house p__p__x), and so on.
We know that:
- When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1.
- When the penguin starts walking from any house indexed from k + 1 to n, inclusive, he definitely cannot walk to house number 1.
- When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house.
You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109 + 7).
小企鹅波洛热爱他的家乡村庄。村庄里有 n 座房子,编号为 1 到 n 的整数。每座房子门口都有一块标牌,上面写有一个整数;第 i 座房子的标牌上写的整数为 pi(其中 1≤pi≤n)。
小企鹅波洛喜欢在村庄中散步。散步过程如下:他首先站在编号为 x 的房子前;然后前往标牌上写着的编号所对应的房子(即前往编号为 px 的房子);接着再前往该房子标牌上所写编号对应的房子(即前往编号为 ppx 的房子),依此类推。
已知以下三点:
- 当企鹅从编号为 1 至 k(含端点)的任意一座房子出发时,他最终都能到达编号为 1 的房子;
- 当企鹅从编号为 k+1 至 n(含端点)的任意一座房子出发时,他一定无法到达编号为 1 的房子;
- 当企鹅从编号为 1 的房子出发时,经过若干次(非零次数)从一座房子走到另一座房子后,他可以回到编号为 1 的房子。
你需要计算:满足上述三个条件的标牌数字 p1,p2,…,pn 的填写方案总数。请输出该总数对 1000000007(即 109+7)取模的结果。
输入格式
The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ min(8, n)) — the number of the houses and the number k from the statement.
单行包含两个以空格分隔的整数 n 和 k(1 ≤ n ≤ 1000,1 ≤ k ≤ min(8, n))——分别为房屋的数量以及题目描述中的数 k。
输出格式
In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
在一行中输出一个整数——该问题答案对 1000000007(即 109+7)取模的结果。
输入输出样例
输入#1
5 2
输出#1
54
输入#2
7 4
输出#2
1728
输入解题思路,AI测评打分。不知道怎么写?