CF288B.Polo the Penguin and Houses

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Little penguin Polo loves his home village. The village has nn houses, indexed by integers from 1 to nn . Each house has a plaque containing an integer, the ii -th house has a plaque containing integer pip_{i} ( 1<=pi<=n1<=p_{i}<=n ).

Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number xx . Then he goes to the house whose number is written on the plaque of house xx (that is, to house pxp_{x} ), then he goes to the house whose number is written on the plaque of house pxp_{x} (that is, to house ppxp_{px} ), and so on.

We know that:

  1. When the penguin starts walking from any house indexed from 1 to kk , inclusive, he can walk to house number 1.
  2. When the penguin starts walking from any house indexed from k+1k+1 to nn , inclusive, he definitely cannot walk to house number 1.
  3. 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 10000000071000000007 (109+7)(10^{9}+7) .

输入格式

The single line contains two space-separated integers nn and kk ( 1<=n<=1000,1<=k<=min(8,n)1<=n<=1000,1<=k<=min(8,n) ) — the number of the houses and the number kk from the statement.

输出格式

In a single line print a single integer — the answer to the problem modulo 10000000071000000007 (109+7)(10^{9}+7) .

输入输出样例

  • 输入#1

    5 2
    

    输出#1

    54
    
  • 输入#2

    7 4
    

    输出#2

    1728
    
首页