合唱队

区间do

大力设状态,设dp[i][j][0/1]代表左右端点位i,j的区间,最后加入的是左端点还是右端点。转移:

// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#define maxn 1006
#define int long long
#define SZJ signed
#include<time.h>
#define AK main
#define half (l+r)>>1
#define SDOI () 
#define mod 19650827
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i) 
#define dep(i,a,b) for (int i=a;i>=b;i--)  
#define erpe (i,a) for (int i=head[a];i!=-1;i=e[i].next)
#define lson t[s].lc
#define rson t[s].rc
int num[maxn],dp[maxn][maxn][3],n;
inline int dfs(int l,int r,int now)
{
    if (~dp[l][r][now]) return dp[l][r][now];
    int tmp=0;
    if (l==r) return (now==0);
    if (now==0)
    {
        if (num[l]<num[l+1]) tmp+=dfs(l+1,r,0),tmp%=mod;
        if (num[l]<num[r]) tmp+=dfs(l+1,r,1),tmp%=mod;
    }
    else 
    {
        if (num[r]>num[r-1]) tmp+=dfs(l,r-1,1),tmp%=mod;
        if (num[r]>num[l]) tmp+=dfs(l,r-1,0),tmp%=mod;
    }
    return dp[l][r][now]=tmp;
}
SZJ AK SDOI
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    rep(i,1,n) scanf("%lld",&num[i]);
    int tmpp=dfs(1,n,0)+dfs(1,n,1);
    cout<<tmpp%mod;
    return 0;
}
posted @ 2018-11-07 12:29  Splitor  阅读(127)  评论(0编辑  收藏  举报