【贪心】HDU 1257
题意:中文题不解释。
思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度。输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最高拦截高度比它高,就把当前拦截系统的高度调整为它的高度,如果访问到末尾都没有能拦截的系统,那么拦截系统加一。
P.S:听说这题杭电数据有点水
/**
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
**/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 300005;
int dp[maxn];
int n;
int main()
{
while(~scanf("%d",&n)){
memset(dp,0,sizeof(dp)); //仅仅需要dp[0] = 0就可以
int flag; //标记是否能被当前已有的拦截系统拦截
int x;
int res = 0;
for(int i=0;i<n;i++){
scanf("%d",&x);
flag = 1;
for(int j=0;j<=res;j++){
if(dp[j]>x){
dp[j] = x;
flag = 0;
break;
}
}
if(flag){
res++;
dp[res] = x;
}
}
printf("%d\n",res);
}
return 0;
}
【贪心】HDU 1257的更多相关文章
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 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 ...
- 怒刷DP之 HDU 1257
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257——最少拦截系统——————【LIS变型题】
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257 最少拦截系统 最长递增子序列
HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...
- hdu 1257 最少拦截系统(简单贪心)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1257 虽然分类是dp感觉还是贪心 比较水 #include <iostream> #inclu ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
- HDU 1257 最少拦截系统(贪心 or LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 设置session生存时间问题
// 在 php.ini 中设置 session.gc_maxlifetime = 1440 (默认) // 或者在 session_start() 前,设置 $lifetime = 86400 , ...
- $q -- AngularJS中的服务(理解)
描述 译者注: 看到了一篇非常好的文章,如果你有兴趣,可以查看: Promises与Javascript异步编程 , 里面对Promises规范和使用情景,好处讲的非常好透彻,个人觉得简单易懂. ...
- C#数字日期装换为中文日期
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- tornado中将cookie值设置为json字符串
不熟悉,找了很久,能FQ的话, https://groups.google.com/forum/#!topic/python-tornado/9Y--NgwjP_w 2楼有解释. tornado.es ...
- cookie和Session
好文推荐:http://blog.csdn.net/fangaoxin/article/details/6952954(Cookie/Session机制详解) Cookie的属性 name :cook ...
- Windows Server 2008 双网卡同时上内外网 不能正常使用
Windows server 2008 32位下,双网卡同时上内外网,并提供VPN服务,遇见的奇怪问题 1.服务器配置 2.网络配置 以太网适配器 内部连接: 连接特定的 DNS 后缀 . . . . ...
- 【http】四种常见的 POST 提交数据方式
来源:http://www.cnblogs.com/aaronjs/p/4165049.html HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT ...
- October 28th Week 44th Friday 2016
Life is not a problem to be solved, but a reality to be experienced. 人生不是待解决的难题,而是等着我们去体验的现实. Press ...
- Mysql中eft join、right join、inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...
- C#语言实现定时开启或禁用网卡小程序
C#语言实现定时开启/禁用网卡 程序运行效果图 程序实现主要代码 源代码工程文件(VS2013工程文件编译通过) 查看网卡名称附图 1.win7旗舰版运行效果图: 2.程序实现主要代码: /// 网卡 ...