Another Filling the Grid

시간 제한1초메모리 제한1024 MB

요약
각 행과 각 열에 1이 하나 이상 들어가도록 1부터 k까지의 정수로 n×n 격자를 채우는 경우의 수를 1e9+7로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
조합론, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

You have n×nn \times n square grid and an integer kk. Put an integer in each cell while satisfying the conditions below.

  • All numbers in the grid should be between 11 and kk inclusive.
  • Minimum number of the ii-th row is 11 (1≤i≤n1 \le i \le n).
  • Minimum number of the jj-th column is 11 (1≤j≤n1 \le j \le n).

Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo (109+7)(10^{9} + 7).

These are the examples of valid and invalid grid when n=k=2n=k=2.

입력

The only line contains two integers nn and kk (1≤n≤2501 \le n \le 250, 1≤k≤1091 \le k \le 10^{9}).

출력

Print the answer modulo (109+7)(10^{9} + 7).

힌트

In the first example, following 77 cases are possible.

In the second example, make sure you print the answer modulo (109+7)(10^{9} + 7).

예제2

  1. 예제 1

    입력
    2 2
    
    예상 출력
    7
    
  2. 예제 2

    입력
    123 456789
    
    예상 출력
    689974806