Simple DP question. No more water.
---------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define REP (i,n) for (int i=0;i<n;++i)#define CLR (x,c) memset (x,c,sizeof (x) )using namespace std;const int maxn=1000+5;const int mod=19650827;int n;int GOAL[MAXN];int d[maxn][maxn][2];//0 put left, 1 put rightint dp (int l,int r,int op) {int &ans=d[l][r][op];if (ans>=0) return ans;ans=0;if (OP) {if (Goal[l]<goal[r]) ANS=DP (l,r-1,0);if (l!=r-1 && goal[r-1]<goal[r]) (ANS+=DP (l,r-1,1))%=mod;} else {if (Goal[l+1]>goal[l]) ANS=DP (l+1,r,0);if (l+1!=r && goal[r]>goal[l]) (ANS+=DP (l+1,r,1))%=mod;}return ans%=mod;}int main (){//freopen ("test.in", "R", stdin);//freopen ("Test.out", "w", stdout);CLR (d,-1);scanf ("%d", &n);Rep (i,n) d[i][i][0]=d[i][i][1]=1;Rep (i,n) scanf ("%d", &goal[i]);printf ("%d\n", (DP (0,n-1,0) +DP (0,n-1,1))%mod);return 0;}
---------------------------------------------------------------
1996: [Hnoi2010]chorus Chorus time limit: 4 Sec Memory Limit: + MB
Submit: 1045 Solved: 672
[Submit] [Status] [Discuss] Descriptioninputoutputsample Input4
1701 1702 1703 1704Sample Output8HINT
Bzoj 1996: [Hnoi2010]chorus Chorus (DP)