OpenJ_Bailian - 2995-登山(两遍最长上升子序列+枚举顶点)
五一到了,PKU-ACM队组织大家去登山观光,队员们发现山上一个有N个景点,并且决定按照顺序来浏览这些景点,即每次所浏览景点的编号都要大于前一个浏览景点的编号。同时队员们还有另一个登山习惯,就是不连续浏览海拔相同的两个景点,并且一旦开始下山,就不再向上走了。队员们希望在满足上面条件的同时,尽可能多的浏览景点,你能帮他们找出最多可能浏览的景点数么?
InputLine 1: N (2 <= N <= 1000) 景点数
Line 2: N个整数,每个景点的海拔Output最多能浏览的景点数Sample Input
8
186 186 150 200 160 130 197 220
Sample Output
4 代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e4+;
typedef long long ll;
using namespace std;
int a[maxn];
int dp1[maxn],dp2[maxn];
int main()
{
int n; cin>>n;
for(int t=;t<=n;t++)
{
scanf("%d",&a[t]);
}
for(int t=;t<=n;t++)
{
dp1[t]=;
dp2[t]=;
}
for(int t=;t<=n;t++)
{
for(int j=;j<t;j++)
{
if(a[t]>a[j])
dp1[t]=max(dp1[t],dp1[j]+);
}
}
for(int t=n;t>;t--)
{
for(int j=n;j>t;j--)
{
if(a[t]>a[j])
dp2[t]=max(dp2[t],dp2[j]+);
}
}
int ans=-;
for(int t=;t<=n;t++)
{
ans=max(dp1[t]+dp2[t]-,ans);
}
cout<<ans<<endl;
return ;
} //java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int[] a= new int[];
int[] b= new int[];
int[] dp1=new int[];
int[] dp2=new int[];
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
for(int t=;t<=N;t++)
{
a[t]=sc.nextInt();
}
for(int t=;t<=N;t++)
{
b[N-t+]=a[t];
}
for(int t=;t<=N;t++)
{
dp1[t]=;
dp2[t]=;
}
for(int t=;t<=N;t++)
{
for(int j=;j<t;j++)
{
if(a[t]>a[j])
{
dp1[t]=max(dp1[t],dp1[j]+);
}
}
}
for(int t=;t<=N;t++)
{
for(int j=;j<t;j++)
{
if(b[t]>b[j])
{
dp2[t]=max(dp2[t],dp2[j]+);
}
}
}
int ans=;
for(int t=;t<=N;t++)
{
ans=max(dp1[t]+dp2[N-t+]-,ans);
}
System.out.println(ans);
sc.close();
}
private static int max(int i, int j) {
// TODO 自动生成的方法存根
if(i>j)
return i;
else
return j;
}
}
OpenJ_Bailian - 2995-登山(两遍最长上升子序列+枚举顶点)的更多相关文章
- hdu 4681 最长公共子序列+枚举
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 #include<cstdio> #include<cstring> # ...
- HDU 3998 Sequence (最长上升子序列+最大流)
参考链接:http://www.cnblogs.com/gentleh/archive/2013/03/30/2989958.html 题意:求一个序列的最长上升子序列,及其个数(注意:两个最长上升子 ...
- BZOJ 2423 最长公共子序列
Description 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x0,x1,…,xm-1”,序列Y=“y0, ...
- Leetcode 673.最长递增子序列的个数
最长递增子序列的个数 给定一个未排序的整数数组,找到最长递增子序列的个数. 示例 1: 输入: [1,3,5,4,7] 输出: 2 解释: 有两个最长递增子序列,分别是 [1, 3, 4, 7] 和[ ...
- [BZOJ2423][HAOI2010]最长公共子序列
[BZOJ2423][HAOI2010]最长公共子序列 试题描述 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x ...
- NOIP200407合唱队形+最长上升子序列O(n^2)详解
合唱队形解题报告 2016-05-12 4:30——6:45 NOIP200407合唱队形 难度级别:A: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:20000 ...
- bzoj:2423: [HAOI2010]最长公共子序列
Description 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x0,x1,…,xm-1”,序列Y=“y0, ...
- [Swift]LeetCode673. 最长递增子序列的个数 | Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- codevs 1862 最长公共子序列(求最长公共子序列长度并统计最长公共子序列的个数)
题目描述 Description 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x0,x1,…,xm-1”,序列Y ...
随机推荐
- jquery的父级和兄弟级能做多少网页特效
这里说的父级就是parent 兄弟级就是siblings 我这里说一个导航栏用到的特效 主要jquery代码$(this).parent().addClass(“active”).siblings( ...
- qt中使用dll库的方法
使用dll文件时首先通过dll文件导出符号表,如下面介绍 1. 制作def 直接调用 pexports mylib.dll > mylib.def 2. 生成a 需要mylib.dll和myli ...
- MyFirstJavaWeb
源代码: Register.jsp <%@ page language="java" contentType="text/html; charset=utf-8&q ...
- pageHelper使用时的注意点
1 在pom.xml中导入相关的依赖(注意版本问题,报错十有八九是因为版本问题) <dependency> <groupId>com.github.pagehelper< ...
- Java中的引用与ThreadLocal
Java中的引用--强软弱虚 强引用 Object object = new Object(),这个object就是一个强引用.如果一个对象具有强引用,那就类似于必不可少的生活用品,垃圾回收器绝不会回 ...
- C#LeetCode刷题-分治算法
分治算法篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30 ...
- Vue 过滤器 Filter传递参数
给日期类型过滤器设置不同格式 dayjs是一款轻量级的日期操作库 https://day.js.org/en import Vue from 'vue' import dayjs from 'dayj ...
- Flutter 容器(4) - Container
Container 类似于HTML中的div标签 import 'package:flutter/material.dart'; class AuthList extends StatelessWid ...
- Mybatis中选择语句的使用:<choose>标签、分区排序 Row_num() over ()函数的使用呢
1.Mybatis中数据库语句的选择 使用: <choose> <when test="relationType=='L'"> ...
- 重回OI的第一篇博客
太久没学OI了, 代码都不会写了, 先写一篇BFS练练手, 是我太菜了qwq #include<cstdio> #include<queue> #include<iost ...