[luoguP3205] [HNOI2010]CHORUS 合唱队(区间DP)
注意到只能在两边加人,有一种区间dp的感觉。
f[i][j][0/1]表示已经搞完区间[i,j]且上次搞的是左/右的方案数
那么他只能从f[i+1][j]或f[i][j-1]的某种状态得到,随便yy以下就知道状态转移方程了
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 2010
#define p 19650827 using namespace std; int n;
int a[N], f[N][N][2]; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline int dfs(int l, int r, int x)
{
if(f[l][r][x] != -1) return f[l][r][x];
int tmp = 0;
if(!x)
{
if(a[l] < a[l + 1]) tmp += dfs(l + 1, r, 0);
if(a[l] < a[r]) tmp += dfs(l + 1, r, 1);
}
else
{
if(a[r] > a[l]) tmp += dfs(l, r - 1, 0);
if(a[r] > a[r - 1]) tmp += dfs(l, r - 1, 1);
}
return f[l][r][x] = tmp % p;
} int main()
{
int i;
n = read();
memset(f, -1, sizeof(f));
for(i = 1; i <= n; i++)
{
a[i] = read();
f[i][i][0] = 1;
f[i][i][1] = 0;
}
printf("%d\n", (dfs(1, n, 0) + dfs(1, n, 1)) % p);
return 0;
}
[luoguP3205] [HNOI2010]CHORUS 合唱队(区间DP)的更多相关文章
- 【BZOJ1996】[Hnoi2010]chorus 合唱队 区间DP
[BZOJ1996][Hnoi2010]chorus 合唱队 Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Ou ...
- BZOJ1996:[HNOI2010]CHORUS 合唱队(区间DP)
Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Output 8 HINT Solution 辣鸡guide真难用 ...
- [HNOI2010]CHORUS 合唱队 (区间DP)
题目描述 对于一个包含 NN 个整数的数列 AA ,我们可以把它的所有元素加入一个双头队列 BB . 首先 A1A1 作为队列的唯一元素,然后依次加入 A2∼ANA2∼AN ,如果 Ai<Ai− ...
- 【BZOJ1996】【HNOI2010】合唱队 [区间DP]
合唱队 Time Limit: 4 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Input Output Sample ...
- LG3205/BZOJ1996 「HNOI2010」合唱队 区间DP
区间DP 区间DP: 显然是一个区间向左右拓展形成的下一个区间,具有包含关系,所以可以使用区间DP. 状态设计: 考虑和关路灯一样设计状态 因为不知道当前这个区间是从哪个区间拓展而来,即不知道这个区间 ...
- 【BZOJ】1996: [Hnoi2010]chorus 合唱队【区间dp】
1996: [Hnoi2010]chorus 合唱队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 2088 Solved: 1371[Submit][ ...
- BZOJ 1996: [Hnoi2010]chorus 合唱队(dp)
简单的dp题..不能更水了.. --------------------------------------------------------------- #include<cstdio&g ...
- bzoj1196:[Hnoi2010]chorus 合唱队
这数据范围明显的区间dp啊...然而据说二维会wa...那就写三维把... #include<cstdio> #include<cstring> #include<cct ...
- 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 ...
随机推荐
- 用virtualenv构建一个新的python环境,这个新的环境在这个创建的文件夹下
http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143271210830032 ...
- pycharm 安装插件 支持markdown
github项目中的README文件通常是md格式的,但是pycharm默认是不支持的,需要安装插件 进入settings中搜索plugins,然后在plugins中搜索markdown suppor ...
- Mybatis自查询递归查找子
先看一下数据库 主键id,名称product_code,父parent,和kind 设计菜单类 setter,getter Dao public interface ProductMapper { L ...
- hello spring boot neo4j
新建springboot 项目: https://www.cnblogs.com/lcplcpjava/p/7406253.html bug fixs: 1. Maven Configuration ...
- python字典按照k,v来排序
按照 k 排序 按照 v 排序
- MySQL解决中文编码问题
转载组员博客 地址:MySQL解决中文编码问题
- Shell脚本使用汇总整理——mysql数据库5.7.8以前备份脚本
Shell脚本使用汇总整理——mysql数据库5.7.8以前备份脚本 Shell脚本使用的基本知识点汇总详情见连接: https://www.cnblogs.com/lsy-blogs/p/92234 ...
- tcl之基本语法—1
- 使用U盘给笔记本重做系统
**一.戴尔 Vostro 14 3000 Series **1. 开机时快速按F12进入BIOS界面 **2. 按照下图进行一系列的处理,把U盘被设置为第一启动项 **3. 插入U盘后进入老毛桃PE ...
- A1083 List Grades (25)(25 分)
A1083 List Grades (25)(25 分) Given a list of N student records with name, ID and grade. You are supp ...