解题思路:可以转化为求最长上升子序列来做,还是可以用an与按升序排列后的an求LCS来做,为防止超时,用滚动数组优化一下就可以了。

最少拦截系统

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20625    Accepted Submission(s): 8174

Problem Description

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.

Input

输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)

Output

对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.

Sample Input

8 389 207 155 300 299 170 158 65

Sample Output

2

Source

浙江工业大学第四届大学生程序设计竞赛

#include<stdio.h>
#include<string.h>
int a[10010],b[10010],f[2][10010];
void bubblesort(int a[],int n)
{
int i,j,t;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t; }
}
}
}
int max(int c,int d)
{
if(c>d)
return c;
else
return d;
} int main()
{
int i,j,n,x,y;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
bubblesort(a,n);
memset(f,0,sizeof(f)); for(i=1;i<=n;i++)
{
x=i%2;
y=1-x;
for(j=1;j<=n;j++)
{
if(b[i-1]==a[j-1])
f[x][j]=f[y][j-1]+1;
else
f[x][j]=max(f[y][j],f[x][j-1]); }
}
printf("%d\n",f[n%2][n]);
}
}

  

HDU 1257 最少拦截系统【最长上升子序列】的更多相关文章

  1. HDU 1257 最少拦截系统 最长递增子序列

    HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...

  2. hdu 1257 最少拦截系统 求连续递减子序列个数 (理解二分)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. HDU 1257 最少拦截系统(贪心 or LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)   ...

  4. HDU 1257最少拦截系统[动态规划]

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257                                                 最 ...

  5. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

  6. HDU 1257 最少拦截系统(Dilworth定理+LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. hdu 1257 最少拦截系统【贪心 || DP——LIS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  8. HDU 1257——最少拦截系统——————【LIS变型题】

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  9. HDU 1257 最少拦截系统 (DP || 贪心)

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

随机推荐

  1. Multitier architecture-n-tier architecture

    In software engineering, multitier architecture (often referred to as n-tier architecture) or multil ...

  2. Python基础:条件判断 &&循环

    1:条件判断 2:循环 2.1:for 2.2  while 小结: continue :跳出本次循环 进行下次循环,  break :结束循环体.

  3. 路飞学城Python-Day141

    什么是爬虫    爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 爬虫的目的就是为了模拟浏览器进行网络数据访问               抓取数据的两种方式          ...

  4. js将timestamp对象与时间字符串之间的转换

    1. 时间戳转日期字符串 var timestamp = timestampObj.time;获取时间戳的毫秒数 var d = new Date(timestamp); //根据时间戳生成的时间对象 ...

  5. Java 习惯用法总结

    转自:http://www.importnew.com/15605.html 首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 我要投稿 更多频道 » Java 习惯用法总结 2015/04/ ...

  6. N1-1 - 树 - Minimum Depth of Binary Tree

    题目描述: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the ...

  7. N3-1 - 数组 - convert-sorted-array-to-binary-search-tree

    题目描述: Given an array where elements are sorted in ascending order, convert it to a height balanced B ...

  8. spring data JPA使用quartz定时器的具体实现

    第一步.在pom.xml中的配置 <!--quartz--> <dependency> <groupId>org.quartz-scheduler</grou ...

  9. 使用gson进行数据(集合数据)的转换 并且返回给前端 进行动态解析 并添加

    后台使用gson转换工具把list集合数据 以json字符串的方式返回给前台 解压: 加入到工程中 前台页面进行数据解析时  需要把得到的字符串  转换为object数组 -------------- ...

  10. svn查看工程版本库的url地址

    打开cmd,cd到工程目录,使用svn的命令:svn info 完.