hdoj 1257 DP||贪心
最少拦截系统
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38985 Accepted Submission(s): 15293
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
#include "cstdio"
#include "algorithm"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
typedef long long ll;
using namespace std;
const int N=1e6+;
const int mod=1e9+;
#define db double
//int a[N];
//set<int> q;
//map<int ,int > u;
//ll dp[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]);
}
for(int i=;i<n;i++){
dp[i]=;
}
int ans=-;
for(int i=;i<n;i++){
for(int j=;j<i;j++){
if(a[i]>a[j]){
dp[i]=max(dp[i],dp[j]+);
ans=max(dp[i],ans);
} }
}
printf("%d\n",ans);
}
return ;
}
贪心代码:
#include "cstdio"
#include "algorithm"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
typedef long long ll;
using namespace std;
const int N=1e6+;
const int mod=1e9+;
#define db double
//int a[N];
//set<int> q;
//map<int ,int > u;
//ll dp[N];
int a[N];
int h[N];
int main()
{
int n;
while (scanf("%d",&n)==){
memset(h,, sizeof(h));
int v=;
for(int i=;i<n;i++)
scanf("%d",&a[i]);
h[]=a[];
for(int i=;i<n;i++){
if(a[i]<=h[v]){
for(int j=;j<=v;j++){
if(a[i]<=h[j]) {h[j]=a[i];break;}
}
}
else h[++v]=a[i];
}
printf("%d\n",v);
}
return ;
}
hdoj 1257 DP||贪心的更多相关文章
- HDOJ.1257 最少拦截系统 (贪心)
最少拦截系统 点我挑战题目 题意分析 一开始理解错了这道题.这么多个导弹排好序不只需要1个拦截系统吗.后来发现自己真傻.那出这个题还有啥意思,反正都需要一个.(:′⌒`) 给出n个导弹,这n个导弹的顺 ...
- HDOJ 1257 最少拦截系统 【DP】
HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 【bzoj4027】[HEOI2015]兔子与樱花 树形dp+贪心
题目描述 很久很久之前,森林里住着一群兔子.有一天,兔子们突然决定要去看樱花.兔子们所在森林里的樱花树很特殊.樱花树由n个树枝分叉点组成,编号从0到n-1,这n个分叉点由n-1个树枝连接,我们可以把它 ...
- BZOJ 2021 [Usaco2010 Jan]Cheese Towers:dp + 贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i]( ...
- 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)
洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- hdu 1257/1800 - 贪心,dp
1257题目链接 一个序列划分子序列,每个子序列都是非增序列,问最少分成几个子序列 1800题目链接 一堆数分组,每组内数据严格递减,问最少分几组 -------------------------- ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
随机推荐
- PHP 绘图技术
1.图片格式:目前网站开发常见的图片格式有gif,jpg/jpeg,png ..... 区别: gif 图片压缩率高,但是只能显示256色,可能造成颜色的丢失,可以显示动画 jpg/jpeg 图片压缩 ...
- apache 做负载
首先说明一下,我感觉这种办法不太好,不能叫负载吧.不知道跳转到的服务器把数据返回给用户,还通不通过Apache的服务器,还有就是不能断点下载了 方法 1.打开httpd.conf 把如下模块前面的# ...
- origin中把多个拟合曲线放在一张图
双击其中一个.或者New一个graph.这里直接双击其中一个图. 右键,找到layer contents. 可以看到,一个scatter配一个polynomial fit line.把剩下的B,C,D ...
- 【angularjs】【学习心得】路由基础篇
原文:http://www.imooc.com/wenda/detail/236998 AngularJS自带有路由模块ngRoute,但是有经验的老师都推荐我们使用功能更完善更强大的ui-route ...
- 我用Cocos2d-x模拟《Love Live!学院偶像祭》的Live场景(五)
[前言和思路整理] 千呼万唤Shǐ出来!终于到最后一章啦~ 很抱歉这一章卡了那么久才发布.主要原因是家里电脑主板的内存插槽炸了,返厂后这周才收到,平时在公司也基本没什么时间写……再次表示歉意. 上一章 ...
- C/C++将一个整型数组拼接成一个字符串
参考: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <stdio.h> #include <string.h> int ma ...
- Ninja介绍
什么是Ninja 在Unix/Linux下通常使用Makefile来控制代码的编译,但是Makefile对于比较大的项目有时候会比较慢,看看上面那副漫画,代码在编译都变成了程序员放松的借口了.所以这个 ...
- 配置FMS发布/HDS/HLS流
一.前言 安装完FMS4.5以后就有了apache2.2,由于在FMS安装目录里面,他是对外面已经安装的是没有影响的,默认情况向, FMS监听80端口接收traffic然后传递给Apache的8134 ...
- Bootstrap入门(十二)组件6:导航标签页
Bootstrap入门(十二)组件6:导航标签页 1.标签页 2.胶囊式标签页 3.垂直展示 4.两端对齐的标签页 5.禁用的链接 6.添加下拉菜单 先引入本地的CSS文件和JS文件(注:1. ...
- es6笔记6^_^generator
1.简介 Generator函数是一个函数的内部状态的遍历器(也就是说,Generator函数是一个状态机). 形式上,Generator函数是一个普通函数,但是有两个特征. function命令与函 ...