简单的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. SQL练习之求解填字游戏

    SELECT * FROM dbo.spt_values

  2. Server.MapPath(string sFilePath) 报未将对象引用到实例异常

    System.Web.HttpContext.Current.Server.MapPath(string sfilePath)将虚拟路径转换成物理路径.这个必须在aspx或者MVC中Action调用才 ...

  3. validate 表单验证

    转自博客园:http://www.cnblogs.com/easyinsc/archive/2009/02/27/1407826.html (1)required:true               ...

  4. Java环境的配置

    JAVA环境: 1.打开我的电脑--属性--高级--环境变量 2.将相应的JDK环境下载到本机,将路径保存到无中文路径中,并将路径复制下来. 3.在环境变量--系统变量,中新建 变量名:JAVA_HO ...

  5. const和readonly你真的懂吗?

    第二遍文章我打算把const和readonly的区别拿出来讲下,因为写代码这么久我都还没搞清楚这两者的区别,实在有点惭愧,所以这一次我打算搞清楚它. 定义 来看看MSDN的解释: readonly:r ...

  6. poj2987 Firing

    以前只是A过很简单的最大闭合权像hdu1565之类,完全的最大流模板题.但是都完全不太懂最大闭合权的定义及其用途. 关于最大流的基础知识,大家可以自己网上搜索关键字.有点基础的哥们妹们,推荐看看胡伯涛 ...

  7. 将窗口置顶的方法:SetWindowPos、AttachThreadInput、SwitchToThisWindow

    将窗口置顶的方法:SetWindowPos.AttachThreadInput.SwitchToThisWindow [转]http://hi.baidu.com/neil_danky/item/f9 ...

  8. HDU 5573 Binary Tree(找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5573 题意:给你一个完全二叉树,节点为自然数的排列(第一行1,第二行2 3,第三行4 5 6 7... ...

  9. BZOJ 1297: [SCOI2009]迷路( dp + 矩阵快速幂 )

    递推式很明显...但是要做矩阵乘法就得拆点..我一开始很脑残地对于每一条权值v>1的边都新建v-1个节点去转移...然后就TLE了...把每个点拆成9个就可以了...时间复杂度O((9N)^3* ...

  10. USACO Section 4.3 Buy low,Buy lower(LIS)

    第一眼看到题目,感觉水水的,不就是最长下降子序列嘛!然后写……就呵呵了..要判重,还要高精度……判重我是在计算中加入各种判断.这道题比看上去麻烦一点,但其实还好吧.. #include<cstd ...