简单的dp题..不能更水了..

---------------------------------------------------------------

#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放入左,1放入右
int 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 合唱队

Time Limit: 4 Sec  Memory Limit: 64 MB
Submit: 1045  Solved: 672
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

4
1701 1702 1703 1704

Sample Output

8

HINT

BZOJ 1996: [Hnoi2010]chorus 合唱队(dp)的更多相关文章

  1. BZOJ 1996: [Hnoi2010]chorus 合唱队(区间dp)

    题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1996 题解: 这题刚拿到手的时候一脸懵逼qwq,经过思考与分析(看题解),发现是一道区间d ...

  2. bzoj 1996: [Hnoi2010]chorus 合唱队

    Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Output 8 HINT Source 因为只会在区间的两端进行 ...

  3. 【BZOJ】1996: [Hnoi2010]chorus 合唱队【区间dp】

    1996: [Hnoi2010]chorus 合唱队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 2088  Solved: 1371[Submit][ ...

  4. 1996: [Hnoi2010]chorus 合唱队 - BZOJ

    Description Input Output Sample Input41701 1702 1703 1704Sample Output8HINT 水题,区间dp,f[l,r,k]表示区间[l,r ...

  5. 1996: [Hnoi2010]chorus 合唱队

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1996 Description Input Output Sample Input 4 1701 ...

  6. BZOJ1996: [Hnoi2010]chorus 合唱队 (DP)

    就是想水一发 #include <stdio.h> #include <algorithm> #include <iostream> using namespace ...

  7. bzoj千题计划211:bzoj1996: [Hnoi2010]chorus 合唱队

    http://www.lydsy.com/JudgeOnline/problem.php?id=1996 f[i][j][0/1] 表示已经排出队形中的[i,j],最后一个插入的人在[i,j]的i或j ...

  8. bzoj1196:[Hnoi2010]chorus 合唱队

    这数据范围明显的区间dp啊...然而据说二维会wa...那就写三维把... #include<cstdio> #include<cstring> #include<cct ...

  9. 【BZOJ1996】[Hnoi2010]chorus 合唱队 区间DP

    [BZOJ1996][Hnoi2010]chorus 合唱队 Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Ou ...

随机推荐

  1. UberX及以上级别车奖励政策(优步北京第一组)

    优步北京第一组: 定义为2015年6月1日凌晨前(不含6月1日)激活的司机(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机( ...

  2. C++_bool

    1 0 #include <iostream> using namespace std; void main() { && || || - && ; std ...

  3. js的replace的用法;

    obj.replace("需要替换的字符串","替换后的字符串")

  4. 对应第一篇文章api的编写

    router.get('/api/tags/search/:list/:key/:page', function(req, res) { if(_.isEmpty(req.params.key)) { ...

  5. Address already in use: JVM_Bind <null>:8080

    解决方法: 1重开eclipse,端口号被占用,或者杀掉进程

  6. c_str()

    1.string类成员函数c_str()的原型: const char *c_str()const;//返回一个以null终止的c字符串 2.c_str()函数返回一个指向正规c字符串的指针,内容和s ...

  7. Httpservlet cannot be resolved to a type

    这个问题与上个问题可以说是“错的类似”.解决方案:就是在Tomcat的lib目录下加入servlet-api.jar 即可.

  8. SQL类型转换以及自动在前面补0满足10位工号标示法

    1,自动在前面补0满足10位工号标示法 SELECT rtrim(ltrim(right(cast('00000000'+rtrim(CAST(数值 as int)) as varchar(20)), ...

  9. ASP.NET MVC 必备知识点杂谈

    一  工程结构4个程序集 Microsoft.Web.Mvc --一些可以使用的,不确定的程序包System.Web.Mvc  --主程序库下面两个列入3.5的Net框架了System.Web.Abs ...

  10. char *p 和char *p[]

    char *p 和char *p[]区别 char* p是一个指针,根本没分配内存,他指向的"abc123ABC" 是只读的,不能改变,在下面给他赋值是错的 而char p[]是一 ...