#include using namespace std; typedef long long ll; typedef pair l_l; typedef pair i_i; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) const ll mod = 1000000007; ll inv[1000000]; ll FactorialInv[1000000]; ll Factorial[1000000]; ll beki(ll a, ll b){ if(b == 0){ return 1; } ll ans = beki(a, b / 2); ans = ans * ans % mod; if(b % 2 == 1){ ans = ans * a % mod; } return ans; } void init_combination(){ inv[1] = 1; FactorialInv[1] = 1; Factorial[1] = 1; Factorial[0] = 1; FactorialInv[0] = 1; inv[1] = 0; for(int i = 2; i < 1000000; i++){ inv[i] = beki(i, mod - 2); Factorial[i] = Factorial[i - 1] * i % mod; FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod; } } ll combination(ll a, ll b){ if((a == b) || (b == 0)){ return 1; } ll ans = Factorial[a] * FactorialInv[b] % mod; ans = ans * FactorialInv[a - b] % mod; return ans; } ll N, K; ll dp[305][305][305]; //dp[i][j][k]:iターン経過時点で、境界直前の駒がjマス移動、境界直後のコマがkマス移動している確率 //ただし、途中で境界直後のコマが境界直前のコマに追いついてはいけない ll dp2[305][305]; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); init_combination(); cin >> N >> K; if(N==1) { cout << 0 << endl; return 0; } dp[0][0][0] = 1; ll sum = 0; for(int time = 0; time <= K; time++) { for(int before = 0; before <= time; before++) { for(int after = 0; after <= time; after++) { //cerr << time << " " << before << " " << after << " " << dp[time][before][after] << endl; dp[time+1][after][before] += dp[time][after][before] * (N-2); dp[time+1][after][before] %= mod; dp[time+1][after+1][before] += dp[time][after][before]; dp[time+1][after+1][before] %= mod; if(after > before) { dp[time+1][after][before+1] += dp[time][after][before]; dp[time+1][after][before+1] %= mod; } } } } dp2[0][0] = 1; for(ll time = 0; time <= K; time++) { for(ll before = 0; before <= time; before++) { dp2[time+1][before] += dp2[time][before] * (N-1); dp2[time+1][before] %= mod; dp2[time+1][before+1] += dp2[time][before]; dp2[time+1][before+1] %= mod; } } ll ans = 0; ll total = 1; for(int i = 1; i <= K; i++) total = (total * N) % mod; //cerr << total << endl; for(ll pos = 1; pos <= N; pos++) { ll ways = total; for(ll cant = pos+1; cant <= N; cant++) { //for(ll arrive1 = 0; arrive1 < pos; arrive1++) { for(ll delta = cant-pos; delta <= K; delta++) { for(ll arrive2 = pos+1; arrive2 <= cant; arrive2++) { ways = (ways - dp[K][delta][cant-arrive2] + mod) % mod; } } //cerr << pos << " " << cant << " " << ways << endl; } //cerr << pos << " " << ways << endl; for(ll arrive = 0; arrive < pos; arrive++) { ways = (ways - dp2[K][N-arrive] + mod) % mod; } //cerr << pos << " " << ways << endl; ans = (ans + ways * pos) % mod; } cout << ans << endl; return 0; }