HDU 1257 最少拦截系统 ——(LIS)
想了一下感觉和lis有关,交了果然AC。想不到很好的证明方法,试做证明如下:lis的每一个点都是一个不上升系统中的一员,设其为a[i],那么a[i-1]<a[i]肯定是成立的(lis的性质),夹在这两者之间的一个元素x,如果其>=a[i],那么它肯定属于a[i]这个系统,如果它小于a[i],且:1.大于a[i-1]的话,违背了lis的性质,2.<=a[i-1]的话,x属于a[i-1]这个系统。不可能有别的情况了。
归纳如下:给定一个序列,它的LIS长度就是它非上升子序列的个数。
代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = + ; int a[N];
int dp[N]; int main()
{
int n;
while(scanf("%d",&n) == )
{
for(int i=;i<=n;i++) scanf("%d",a+i);
memset(dp,inf,sizeof dp);
for(int i=;i<=n;i++)
{
*lower_bound(dp+,dp++n,a[i]) = a[i];
}
printf("%d\n",lower_bound(dp+,dp++n,inf) - (dp+));
}
return ;
}
HDU 1257 最少拦截系统 ——(LIS)的更多相关文章
- HDU 1257 最少拦截系统 最长递增子序列
HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...
- HDU 1257 最少拦截系统(贪心 or LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1257最少拦截系统[动态规划]
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257 最 ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1257——最少拦截系统——————【LIS变型题】
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257 最少拦截系统(Dilworth定理+LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1257 最少拦截系统(动态规划 / 贪心)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1257最少拦截系统
最少拦截系统 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的 ...
随机推荐
- Spring Boot 默认首页
//继承 WebMvcConfigurerAdapter @Override public void addViewControllers(ViewControllerRegistry registr ...
- XML-RPC-3XML-RPC 与 XML-RPC 服务器类
http://codeigniter.org.cn/user_guide/libraries/xmlrpc.html XML-RPC 与 XML-RPC 服务器类 CodeIgniter 的 XML- ...
- 12.java中参数传递机制---形参和实参
1.形参:用来接收调用该方法时传递的参数.只有在被调用的时候才分配内存空间,一旦调用结束,就释放内存空间.因此仅仅在方法内有效. public void swap(int a, int b) { in ...
- HashSet和CopyOnWriteArraySet(转载)
前言 这篇文章的目的如下: HashSet是如何保证元素的不重复和无序 HashSet的增删(改查?)原理 CopyOnWriteArraySet支持并发的原理 CopyOnWriteArraySet ...
- 如何搭建一个基于nuxt.js的项目
介绍 nuxt.js(中文官方文档)是vue.js的一个通用型应用框架,有了之前搭建vue项目的过程之后,搭建一个nuxt项目就会十分简单. 搭建步骤 1.打开命令提示符,进入到相关文件夹下: 2.使 ...
- Oracle nvl()函数处理null值
首先我先说一下什么是Oracle的函数,曾经有一位大牛,让我说说熟悉的oracle函数,我当时竟一头雾水,心想“什么oracle函数啊,不就是那些SQL语句吗“,当时我竟然说出了select之类的回答 ...
- redis集群安装2
概要:本文主要介绍如何在Centos7中单机搭建redis集群三主三从,按照本文绝对可以实现该需求,至于先搭建单机版主要为了方便理解redis集群,为下一步开发或生产上redis集群做铺垫.同时本 ...
- 网页报警提示 This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see https://goo.gl/zmWq3m.
This page includes a password or credit card input in a non-secure context. A warning has been added ...
- vue sample
<template> <section> <header class="top_tips"> <span class="num_ ...
- java 基础:方法调用中的值传递是call by value,并且传递的是参数的值的拷贝,而不是引用
public class TestExtends { public static void main(String[]args){ int s = 10; System.out.println(Sys ...