bzoj1996
区间dp
其实我们发现对于一段区间我们是这样构造的,每次我们会向两端放数,这样就有四种情况,且必须满足题意,初值是dp[i][i][0]=1,因为第一个人只有一种放法,不分左右。其实看见dp[i][i][0/1]=1时答案是16就改初值
#include<bits/stdc++.h>
using namespace std;
const int N = , mod = ;
int n;
int h[N], dp[N][N][];
void up(int &x, int d)
{
x = (x + d) % mod;
}
int dfs(int l, int r, int f)
{
if(l == r) return f;
if(dp[l][r][f] != -) return dp[l][r][f];
int &ret = (dp[l][r][f] = );
if(f == )
{
if(h[l] < h[l + ]) up(ret, dfs(l + , r, f));
if(h[l] < h[r]) up(ret, dfs(l + , r, f ^ ));
}
else
{
if(h[r] > h[r - ]) up(ret, dfs(l, r - , f));
if(h[r] > h[l]) up(ret, dfs(l, r - , f ^ ));
}
return ret;
}
int main()
{
memset(dp, -, sizeof(dp));
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &h[i]);
printf("%d\n", (dfs(, n, ) + dfs(, n, )) % mod);
return ;
}
bzoj1996的更多相关文章
- 【BZOJ1996】合唱队(动态规划)
[BZOJ1996]合唱队(动态规划) 题面 BZOJ 题解 很容易的一道题 因为每个人不是放在了左边就是放在了右边 所以每次放好的人必定是原序列的一个子串 所以,很容易想到区间\(dp\) 设\(f ...
- BZOJ1996 HNOI2010合唱队(区间dp)
设f[i][j][0/1]表示i~j这段区间上一次选择的是最左/最右人的方案数.转移显然. #include<iostream> #include<cstdio> #inclu ...
- 【BZOJ1996】[Hnoi2010]chorus 合唱队 区间DP
[BZOJ1996][Hnoi2010]chorus 合唱队 Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Ou ...
- BZOJ1996 [Hnoi2010]chorus 合唱队
很容易想到区间DP 然后发现这个区间只和圆序列的最后一个数有关,而原序列的最后一个数只可能是现在区间的头或者尾 令$f[i][j][0/1]$表示在区间$[i, j]$之间,原序列的最后一个数是当前区 ...
- BZOJ1996 合唱队 区间DP
OJ地址:http://www.lydsy.com/JudgeOnline/problem.php?id=1996 设dp(i,j,k)代表在理想结果中[i,j]段最后添加的是i或j(k=0or1) ...
- 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 ...
- BZOJ1996 [Hnoi2010] 合唱队
Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Output 8 HINT Solution 令$f_{i,j}$ ...
- [BZOJ1996] chorus合唱队
Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Output 8 HINT 区间$dp$,首先每个点被放入队伍时队 ...
- BZOJ1996:[HNOI2010]CHORUS 合唱队(区间DP)
Description Input Output Sample Input 4 1701 1702 1703 1704 Sample Output 8 HINT Solution 辣鸡guide真难用 ...
- 【BZOJ1996】【HNOI2010】合唱队 [区间DP]
合唱队 Time Limit: 4 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Input Output Sample ...
随机推荐
- cut printf awk sed grep笔记
名称 作用 参数 实例 cut 截取某列,可指定分隔 -f 列号 -d 分隔符 cut -d ":" -f 1, 3 /etc/passwd 截取第一列和第三列 printf pr ...
- sqlmap sql 注入攻击
- DOS环境进入及基本命令
DOS:磁盘操作系统(Disk Operating System) Window环境下如何进入DOS: 1. 以win10为例,按ctrl+R打开运行窗口,在输入框输入"CMD"并 ...
- 转:Python yield 使用浅析 from IBM Developer
评注:没有看懂. 转: https://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ Python yield 使用浅析 初 ...
- 处理页面载入图片js(等比例压缩图片)
第一页面html <div class="admin">${answer.content}</div> <div class="admin ...
- centos6.3升级python至2.7.5
centos6.3自带的python版本是2.6.6,有时候需要升级到2.7.这里记录一下升级过程,方便查阅.实际上是转载自http://flyingdutchman.iteye.com/blog/1 ...
- 死去活来的OC NSArray 中文排序 及输出
目的 1.NSArray 能够支持中文排序 2.NSLog 能够直接输出 NSArray 内的中文(事实上 java 直接打印数组也不能显示内容哈) 又是死去活来的搞了1个小时,分类实现.废话少说,上 ...
- Hibernate quick start
Preface Working with both Object-Oriented software and Relational Databases can be cumbersome and ti ...
- C语言的一些特殊使用方法————————【Badboy】
一:特殊的字符串宏 [cpp] #define A(x) T_##x #define B(x) #@x #define C(x) #x 我们如果x=1, 则上面的宏定义会被解释成下面的样子 A(1)- ...
- RDLC后台自己定义报表模板
首先封装一个公共类,统一来操作RDLC报表 using System; using System.Collections.Generic; using System.Linq; using Syste ...