简单的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. C++_auto

    自动变量,自动获取类型,输出,泛型 自动变量,可以实现自动循环一维数组 自动循环的时候,对应的必须是常量 //auto自动变量,自动匹配类型 #include <iostream> usi ...

  2. Saiku如何固定查询结果table的表头和首列

    在使用saiku查询的时候,当“行”和“列”的维度内容过多时,在查看时只看到数据,不知道是什么数据,维度不清楚,得来回拖动滚动条才行,所以同事提出想要固定“表头”和“首列”. 在网上找了一些现成的插件 ...

  3. C++与AS3

    ActionScript 3(简称AS3)与 c++ 都是面向对象的编程(OOP)语言,都具有OOP的特性如封装.继承.多态等.二者在语法上有许多相似之处,基本上学过C++之后再学习AS3感觉并不是特 ...

  4. SDOTOJ2088 refresh的停车场(栈和队列)

     refresh的停车场 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit S ...

  5. 得到client真IP住址

    1.引进的必要性log4j-1.2.14.jar package org.ydd.test; import java.util.Enumeration; import javax.servlet.ht ...

  6. 总结:C#变量,占位符等相关知识

    新年耽误了不少时间,好久没认真的坐下来学习了,新年也快完了,又要开始正式学习了,按着视频教学学习,用了一天的时间,学习了下简单的变量及其相关的输入输出和应用,学了几种最基本的类型: int(整型) c ...

  7. md笔记——微信JS接口

    微信js接口 隐藏微信中网页右上角按钮 document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { Weix ...

  8. python文件目录遍历保存成xml文件代码

    Linux服务器有CentOS.Fedora等,都预先安装了Python,版本从2.4到2.5不等,而Windows类型的服务器也多数安装了Python,因此只要在本机写好一个脚本,上传到对应机器,在 ...

  9. 【Java并发编程】并发编程大合集-值得收藏

    http://blog.csdn.net/ns_code/article/details/17539599这个博主的关于java并发编程系列很不错,值得收藏. 为了方便各位网友学习以及方便自己复习之用 ...

  10. 浅谈Hash函数

    什么是hash函数: hash函数也可以翻译成“散列”函数,一般就使用音译“哈希”函数,简单的说哈希函数是对任意长度的输入进行的压缩映射,所谓的压缩映射顾名思义,输出通常来说要比输入短,并且得到的输出 ...