#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"set" #include"vector" #include"map" #include"cmath" #define MAXN 506 //#define int long long usingnamespace std; typedeflonglong ll; #define P 1000000007
int n , m;
intPow( int x , int a ){ int ans = 1 , cur = x % P; while( a ) { if( a & 1 ) ans = 1ll * ans * cur % P; cur = 1ll * cur * cur % P , a >>= 1; } return ans; } int h[MAXN]; int J[1000006] , invJ[1000006]; intC( int a , int b ){ if( a < b ) return0; return1ll * J[a] * invJ[b] % P * invJ[a - b] % P; } intS( int n , int m , int k ){ return1ll * C( n , k ) * C( m , k ) % P * J[k] % P; } int dp[506 * 506][506] , cur , k; intsolve( int l , int r , int base ){ if( l > r ) return0; int re = 0 , c = ++ cur , L = r - l + 1; for( int i = l ; i <= r ; ++ i ) if( !re || h[i] < h[re] ) re = i; vector<int> mn; mn.push_back( l - 1 ); for( int i = l ; i <= r ; ++ i ) if( h[i] == h[re] ) mn.push_back( i ); mn.push_back( r + 1 ); dp[c][0] = 1; for( int i = 1 ; i < mn.size() ; ++ i ) { int t = mn[i] , p = mn[i - 1] , l = t - p - 1 , id = solve( p + 1 , t - 1 , h[re] ); if( id == 0 ) continue; for( int j = min( L , k ) ; j >= 0 ; -- j ) for( int k = 1 ; k <= min( j , l ) ; ++ k ) ( dp[c][j] += 1ll * dp[id][k] * dp[c][j - k] % P ) %= P; } int dh = h[re] - base; for( int i = min( L , k ) ; i >= 0 ; -- i ) for( int j = 1 ; j <= min( dh , i ) ; ++ j ) ( dp[c][i] += 1ll * dp[c][i - j] * S( dh , L - ( i - j ) , j ) % P ) %= P; return c; }
intmain(){ J[0] = 1; invJ[0] = 1; for( int i = 1 ; i < 1000006 ; ++ i ) J[i] = 1ll * J[i - 1] * i % P , invJ[i] = Pow( J[i] , P - 2 ); cin >> n >> k; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",h + i); int c = solve( 1 , n , 0 ); cout << dp[c][k] << endl; }