[hdu4513]常规dp
题意:给一个长度为m的序列,从里面选出一些数,相对位置不发生变化,并满足a[i]=a[n-i],a[1]<a[2]<...<a[(n+1)/2],n是数的个数,求最大的n
思路:dp[i][j]表示0~i,j~m的答案,则dp[i][j]=dp[l][r]+1+(i<j),其中a[i]=a[j]>a[l]=a[r]&&l<i<=j<r。枚举3个变量i,j,r,维护一个l就行了,o(m^3)。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* ******************************************************************************** */#include <iostream> //#include <cstdio> //#include <cmath> //#include <cstdlib> //#include <cstring> //#include <vector> //#include <ctime> //#include <deque> //#include <queue> //#include <algorithm> //using namespace std; // //#define pb push_back //#define mp make_pair //#define X first //#define Y second //#define all(a) (a).begin(), (a).end() //#define foreach(i, a) for (typeof(a.begin()) it = a.begin(); it != a.end(); it ++) // //void RI(vector<int>&a,int n){a.resize(n);for(int i=0;i<n;i++)scanf("%d",&a[i]);} //void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R> //void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?1:-1; //while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T> //void print(const T t){cout<<t<<endl;}template<typename F,typename...R> //void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T> //void print(T*p, T*q){int d=p<q?1:-1;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;} // //typedef pair<int, int> pii; //typedef long long ll; //typedef unsigned long long ull; // ///* -------------------------------------------------------------------------------- */ //template<typename T>bool umax(T &a, const T &b) { return a >= b? false : (a = b, true);}int a[300], dp[300][300];int main() {#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif // ONLINE_JUDGE int T; RI(T); while (T --) { int n; RI(n); RI(a + 1, a + 1 + n); int p[300] = {}; memset(dp, 0, sizeof(dp)); int ans = 0; for (int i = 1; i <= n; i ++) { for (int j = n; j >= i; j --) { if (a[i] != a[j]) continue; dp[i][j] = 1 + (i < j); for (int k = j + 1; k <= n; k ++) { if (a[k] < a[i]) { if (p[a[k]] && p[a[k]] < i) umax(dp[i][j], dp[p[a[k]]][k] + 1 + (i < j)); } } umax(ans, dp[i][j]); } p[a[i]] = i; } cout << ans << endl; } return 0; //} // // // ///* ******************************************************************************** */ |
[hdu4513]常规dp的更多相关文章
- 常规DP专题练习
POJ2279 Mr. Young's Picture Permutations 题意 Language:Default Mr. Young's Picture Permutations Time L ...
- BZOJ1559[JSOI2009]密码——AC自动机+DP+搜索
题目描述 输入 输出 样例输入 10 2 hello world 样例输出 2 helloworld worldhello 提示 这题算是一个套路题了,多个串求都包含它们的长为L的串的方案数. 显然是 ...
- 洛谷1026(字符串dp)
常规dp.看到数据很小就直接暴力了,没有预处理.kmp好像过分了-- #include <cstdio> #include <cstring> #include <ios ...
- HihoCoder1339 Dice Possibility(概率DP+母函数)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is possibility of rolling N dice and the sum of the numb ...
- poj 3017 Cut the Sequence(单调队列优化DP)
Cut the Sequence \(solution:\) 这道题出的真的很好,奈何数据水啊! 这道题当时看得一脸懵逼,说二分也不像二分,说贪心也不像贪心,说搜索吧这题数据范围怎么这么大?而且这题看 ...
- 谈谈我近一个半月的dp练习
前请提示:https://www.cnblogs.com/caiyishuai/p/9047991.html 配合这篇文章食用风味更佳哦! 首先十分感谢henry_y提供的50道dp练习,链接在这 ...
- BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MB Description Farm ...
- luogu P2365 任务安排
嘟嘟嘟 如果常规dp,\(dp[i][j]\)表示前\(i\)个任务分\(j\)组,得到 \[dp[i][j] = min _ {k = 0} ^ {i - 1} (dp[k][j - 1] + (s ...
- [HAOI2015]按位或
题目 好神的题啊 我们发现我们求这个东西如果常规\(dp\)的话可以建出一张拓扑图来,但是边的级别高达\(3^n\),转移的时候还要解方程显然不能通过本题 我们考虑神仙的\(min-max\)容斥 设 ...
随机推荐
- Spring5:面向切面
静态代理 缺点:一个真实角色就会产生一个代理角色,代码量会翻倍! 场景:要在写好的实现方法上加入日志功能(公共功能),不要修改原代码 1:原代码 业务接口: package com.spring; p ...
- linux内核第一宏 container_of
内核第一宏 list_entry()有着内核第一宏的美称,它被设计用来通过结构体成员的指针来返回结构体的指针.现在就让我们通过一步步的分析,来揭开它的神秘面纱,感受内核第一宏设计的精妙之处. 整理分析 ...
- Win10桌面美化
捯饬了几个小时终于捯饬好了,没什么特效,就是看起来干净了许多. 用到的小软件: 链接:https://pan.baidu.com/s/1_PSTn0JZ22ZGiMDOdvdWEw提取码:329c 1 ...
- 5. 配置项:rule_files
prometheus配置文件内容: global: # 默认情况下抓取目标的频率. [ scrape_interval: <duration> | default = 1m ] # 抓取超 ...
- thinkphp--导入导出xls文件
/** * 数组转xls格式的excel文件 * @param array $data 需要生成excel文件的数组 * @param string $filename 生成的excel文件名 * 示 ...
- dockerfile构架镜像(8)
nginx镜像的构建 先查看下本地的镜像,选取官网的centos作为base image: [root@server ~]# docker images 创建一个目录专门用来存放的目录,也就是Dock ...
- iscsi的工作原理与优化(2)
2.1 iSCSI协议模型,iscsi[会话层协议,即应用协议] iSCSI使用TCP/IP协议在不稳定网络上进行可靠的数据传输.iSCSI层和标准SCSI集在协议栈中的位置如图1所示.iSCSI层包 ...
- Ubuntu 设置 log 级别
Linux环境下使用rsyslog管理日志 rsyslog linux运维 linux 22.7k 次阅读 · 读完需要 22 分钟 在 Linux 系统中,日志文件记录了系统中包括内核. ...
- Maven+Jmeter+Jenkins的持续集成的新尝试
前言: 这又是一篇迟到很久的文章,四月身体欠佳,根本不在状态. 好了,回到正题,相信大家也在很多博客,看过很多类似乎的文章,那么大家来看看我是如何实现的? 准备工作: 创建一个maven工程 创建一个 ...
- for-loop 与 json.Unmarshal 性能分析概要
原文地址:for-loop 与 json.Unmarshal 性能分析概要 前言 在项目中,常常会遇到循环交换赋值的数据处理场景,尤其是 RPC,数据交互格式要转为 Protobuf,赋值是无法避免的 ...