BZOJ 1996: [Hnoi2010]chorus 合唱队

NOIP级别的题也能出到省选上来

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int p=19650827;
const int N=1000+5;
int f[N][N][2];
bool vis[N][N][2];
int q[N];
int dp(int l,int r,int flag){
	if(vis[l][r][flag])return f[l][r][flag];
	vis[l][r][flag]=1;
	if(l==r)return f[l][r][flag]=flag;
	if(flag)f[l][r][flag]=(dp(l,r-1,0)*(q[r]>q[l])+dp(l,r-1,1)*(q[r]>q[r-1]))%p;
	else f[l][r][flag]=(dp(l+1,r,0)*(q[l]<q[l+1])+dp(l+1,r,1)*(q[l]<q[r]))%p;
	return f[l][r][flag];
}
int main(){
	//freopen("a.in","r",stdin);
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&q[i]);
	printf("%d\n",(dp(1,n,0)+dp(1,n,1))%p);
	return 0;
}
	


你可能感兴趣的:(BZOJ 1996: [Hnoi2010]chorus 合唱队)