Bzoj 1996: [Hnoi2010]chorus Chorus (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.