#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define N 507
#define mod 1000000007
#define ll long long
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
int n,K;
int a[N];
int f[N][N],delta[N];
int main()
{
f[0][0]=1;
n=read(),K=read();
for (int i=1;i<=n;i++)
a[i]=read();
for (int i=1;i<=n;i++)
{
int l,r;
for (l=i;l>1&&a[l-1]<a[i];l--);
for (r=i;r<n&&a[r+1]<a[i];r++);
(f[K][i]+=f[K][i-1])%=mod;
for (int k=K-1;k>=0;k--)
{
delta[l-1]=0;
for (int j=l;j<=r;j++)delta[j]=(delta[j-1]+f[k][j-1])%mod;
for (int j=l;j<=r;j++)(f[k+1][j]+=delta[j])%=mod;
(f[k][i]+=f[k][i-1])%=mod;
(f[k+1][i]+=mod-f[k][i-1])%=mod;
}
}
int ans=0;
for (int i=0;i<=K;i++)
(ans+=f[i][n])%=mod;
printf("%d\n",ans);
}
14621:Tc605
最新推荐文章于 2024-09-04 21:39:45 发布