bzoj1196:[Hnoi2010]chorus 合唱队

这数据范围明显的区间dp啊。。。然而据说二维会wa。。。那就写三维把。。。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeoF(x))
int read(){
    int x=0;char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+c-'0',c=getchar();
    return x;
} 
const int nmax=1e3+5;
const int mod=19650827;
int dp[nmax][nmax][2],a[nmax];
int main(){
    int n=read();
    rep(i,1,n) a[i]=read(),dp[i][i][0]=1;
    rep(j,1,n-1) {
        for(int i=1;i+j<=n;i++){
            dp[i][i+j][0]=((a[i]<a[i+1])*dp[i+1][i+j][0]+(a[i]<a[i+j])*dp[i+1][i+j][1])%mod;
            dp[i][i+j][1]=((a[i+j]>a[i])*dp[i][i+j-1][0]+(a[i+j]>a[i+j-1])*dp[i][i+j-1][1])%mod;
        }
    }
    printf("%d\n",(dp[1][n][0]+dp[1][n][1])%mod);
    return 0;
}

  

1996: [Hnoi2010]chorus 合唱队

Time Limit: 4 Sec  Memory Limit: 64 MB
Submit: 1499  Solved: 963
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

4
1701 1702 1703 1704

Sample Output

8

HINT

 

Source

 
[Submit][Status][Discuss]
posted @ 2016-09-09 21:17  BBChq  阅读(123)  评论(0编辑  收藏  举报