hdu dp 1257 最小拦截系统
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
Output
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
#include<stdio.h>
#include<math.h>
int a[30001],b[30001];
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
b[0]=0;
k=0;
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
for(j=0; j<=k; j++)
{
if(a[i]<b[j])
{
b[j]=a[i];
break;//如果后面的高度比前面的小,则把后面的代替前面的。
}
else if(j==k)
{
k++;//当后面的高度比前面各系统的最小高度都大时,则系统增加1,此时此系统的最小高度为当前值。
b[k]=a[i];
break;
}
}
}
printf("%d\n",k);
}
return 0;
} ////贪心写法
//#include <iostream>
//#include <algorithm>
//
//using namespace std;
//
//const int MAX_N = 10000;
//int n;
//int temp[MAX_N];
//
//int main()
//{
// while(cin >> n)
// {
// int k = 0;
// bool flag = false;
// int height;
// cin >>height;
// temp[0] = height;
// k++;
// for(int i = 1; i < n; i++)
// {
// flag = false;
// cin >> height;
// //sort(temp,temp + k);
// for(int j = 0; j < k; j++)
// {
// if(temp[j] > height)
// {
// temp[j] = height;
// flag = true;
// break;
// }
// }
// if(!flag)
// temp[k++] = height;
// }
// cout << k << endl;
// }
// return 0;
//}
//
//
//
//
hdu dp 1257 最小拦截系统的更多相关文章
- (hdu)1257 最少拦截系统
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1257 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦 ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 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)\)一样,子序列只要 ...
- HDU 1257最少拦截系统[动态规划]
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257 最 ...
- HDOJ 1257 最少拦截系统 【DP】
HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU1257 最小拦截系统 【贪婪】
最小拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257(最小拦截系统)
Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不 能超过前一发的高度.某天,雷达 ...
随机推荐
- Linux系统调用和库函数
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unist ...
- 将oh-my-zsh编程真正的my zsh
环境: Ubuntu 32位 oh-my-zsh安装: 1.安装zsh: sudo apt-get install zsh 2.将当前用户的shell环境修改为zsh: chsh -s /bin/z ...
- 搭建Elasticsearch5.6.8 分布式集群
集群搭建 1.master[192.168.101.175] 配置elasticsearch.yml #集群名称 所有节点要相同 cluster.name: my-application #本节点名称 ...
- 2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)
题目链接 Problem Description The school set up three elective courses, assuming that these courses are A ...
- Django之原生Ajax操作
Ajax主要就是使用 [XmlHttpRequest]对象来完成请求的操作,该对象在主流浏览器中均存在(除早起的IE),Ajax首次出现IE5.5中存在(ActiveX控件). 先通过代码来看看Aja ...
- VC进度条的使用
m_progress->GetPos(); //获取进度条的当前位置 m_progress->GetRange(int min,int max); //获取进度条控件的范围的下限和上限 m ...
- windows下面安装Python和pip教程
第一步,先来安装Python.windows下面的Python安装一般是通过软件安装包安装而不是命令行,所以首先要在Python的官方主页上面下载最新的Python安装包.下载地址是:https:// ...
- HTML表单属性与全局属性
1.全局属性
- Perl6多线程3: Promise start / in / await
创建一个Promise 并自动运行: my $p = Promise.start({say 'Hello, Promise!'}); 如果把代码改成如下, 我们会发现什么也没打印: ;say 'Hel ...
- openjudge-NOI 2.6-1996 登山
题目链接:http://noi.openjudge.cn/ch0206/1996/ 题解: 正反求两次LIS即可 #include<cstdio> #include<cstring& ...