HDOJ 1257 最少拦截系统 【DP】
HDOJ 1257 最少拦截系统 【DP】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50753 Accepted Submission(s): 19895
Problem Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
题意
求最大上升子序列
AC代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e4 + 5;
const int MOD = 1e9 + 7;
int arr[maxn], dp[maxn];
int main()
{
int n;
while (cin >> n)
{
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
memset(dp, 0, sizeof(dp));
int ans = 0;
for (int i = 0; i < n; i++)
{
dp[i] = 1;
for (int j= i - 1; j >= 0; j--)
{
if (arr[i] > arr[j])
dp[i] = max(dp[i], dp[j] + 1);
}
if (dp[i] > ans)
ans = dp[i];
}
cout << ans << endl;
}
}
HDOJ 1257 最少拦截系统 【DP】的更多相关文章
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDOJ.1257 最少拦截系统 (贪心)
最少拦截系统 点我挑战题目 题意分析 一开始理解错了这道题.这么多个导弹排好序不只需要1个拦截系统吗.后来发现自己真傻.那出这个题还有啥意思,反正都需要一个.(:′⌒`) 给出n个导弹,这n个导弹的顺 ...
- hdoj 1257 最少拦截系统
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- hdoj 1257最少拦截系统
/*最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- LIS HDOJ 1257 最少拦截系统
题目传送门 题意:中文题面 分析:LIS模板题:n - 最长下降子序列 -> 最长上升子序列 贪心做法以后再补:) 代码: #include <cstdio> #include &l ...
- HDU 1257 最少拦截系统(贪心 or LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1257 最少拦截系统 最长递增子序列
HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...
随机推荐
- Oracle Tuning ( instance 级别 ) 01
Shared Pool Tuning 目标是提高命中率, 以减少 I/O 操作 shared pool : 是由 library cache, data dictionary cache 两部分组成. ...
- PAT005 Path in a Heap
题目: Insert a sequence of given numbers into an initially empty min-heap H. Then for any given index ...
- 几个比较经典的算法问题的java实现
1.八皇后问题 public class EightQueen { private static final int ROW = 16; private static final int COL = ...
- WinCC7.3 Win764位系统安装教程
WinCC7.3 Win764位安装教程 (1)将ISO文件解压缩. (2)编辑Setup.ini文件 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/fo ...
- 【Raspberry pi】set up an ftp server
http://www.debian-administration.org/articles/228 As a means of distributing large collections of fi ...
- python 国内镜像
pipy国内镜像目前有: http://pypi.douban.com/ 豆瓣 http://pypi.hustunique.com/ 华中理工大学 http://pypi.sdutlinux.o ...
- ADO访问Oracle数据库,连接异常(Unknown error 0x800a0e7a)
ADO访问Oracle数据库,连接异常(Unknown error 0x800a0e7a) 代码如下:执行Open过程中出现异常,信息为Unknown error 0x800a0e7a C++ Co ...
- 监视EF生成SQL的方法(log , SqlServerProfile)
大家在学习entityframework的时候,都知道那linq写的叫一个爽,再也不用区分不同RDMS的sql版本差异了,但是呢,高效率带来了差灵活性,我们 无法控制sql的生成策略,所以必须不要让自 ...
- javascript 字符串进行 utf8 编码的方法(转)
实践中碰到了一个大问题,在 javascript 中,可能有一些中文字符串,我们想将其进行二进制流编码的时候,需要将其转换为 utf8 的编码. 也就是说,输入的是一个字符串:'呆滞的慢板今天挣了10 ...
- python中 将字符串和字典的相互转换
1.首先引入json模块 # 引入json模块 import json 2.转换 #JSON到字典转化: dictinfo = json.loads(json_str) # 输出dict类型 字典到J ...