1257题目链接

一个序列划分子序列,每个子序列都是非增序列,问最少分成几个子序列

1800题目链接

一堆数分组,每组内数据严格递减,问最少分几组

------------------------------------------------------------------------------------------------

这两个题的区别在于1257数组的排列顺序不能变,而1800只是分组,顺序随意。

1257有两种解法:

一是像hdu1051那样的贪心:像筛素数那样一个序列一个序列的标记。

一是求最长严格递增序列的长度,动态规划做。

而1800只需要统计每个数字出现的次数,找到最大的出现次数,注意前导0

1257贪心代码,0ms

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #define MAX(a,b) ((a)>=(b)?(a):(b))
#define MIN(a,b) ((a)<=(b)?(a):(b))
#define OO 0x0fffffff
typedef long long LL;
using namespace std;
const int N = ;
int hs[N];
bool vis[N];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++) scanf("%d",hs+i);
memset(vis,false,sizeof(vis));
int ans = ;
for(int i=;i<n;i++){
if(!vis[i]){
ans++;
int last = hs[i];
for(int j=i+;j<n;j++){
if((!vis[j])&&hs[j]<=last) last=hs[j],vis[j]=true;
}
}
}
printf("%d\n",ans);
}
return ;
}

1257dp代码,31ms

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #define MAX(a,b) ((a)>=(b)?(a):(b))
#define MIN(a,b) ((a)<=(b)?(a):(b))
#define OO 0x0fffffff
typedef long long LL;
using namespace std;
const int N = ;
int hs[N],dp[N];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++) scanf("%d",hs+i);
int ans = ;
for(int i=;i<n;i++){
dp[i]=;
for(int j=;j<i;j++){
if(hs[j]<hs[i]) dp[i]=MAX(dp[i],dp[j]+);
}
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

1800,用map统计

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #define MAX(a,b) ((a)>=(b)?(a):(b))
#define MIN(a,b) ((a)<=(b)?(a):(b))
#define OO 0x0fffffff
typedef long long LL;
using namespace std;
const int N = ; int main(){
int n,id;
char tmp[];
map<string,int> strs;
while(scanf("%d",&n)!=EOF){
if(!n){puts("");continue;} for(int i=;i<n;i++){
scanf("%s",tmp);
for(id=;id<strlen(tmp);id++){ if(tmp[id]!='') break; }
if(id==strlen(tmp)) id--; if(strs.count(tmp+id)) strs[tmp+id]++;
else strs[tmp+id]=;
}
int ans = ;
for(map<string,int>::iterator iter=strs.begin();iter!=strs.end();iter++)
ans = MAX(ans,iter->second);
printf("%d\n",ans);
strs.clear();
}
return ;
}

hdu 1257/1800 - 贪心,dp的更多相关文章

  1. hdu 5037 Frog 贪心 dp

    哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog ...

  2. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

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

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

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

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

  5. 【贪心】HDU 1257

    HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...

  6. 怒刷DP之 HDU 1257

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

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

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

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

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

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

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

随机推荐

  1. JQuery (总结)

    延迟触发事件 Ajax异步请求数据 Jquery事件: Focus获得焦点 blur失去焦点 Change内容在变化的时候 Click点击事件 ---------------------------- ...

  2. Javascript 正则表达式简述

    本文地址:http://www.cnblogs.com/blackmanba/p/regular-expressions-introduce.html 或者 http://forkme.info/re ...

  3. vue中使用Ueditor编辑器 -- 1

    一.   下载包: 从Ueditor的官网下载1.4.3.3jsp版本的Ueditor编辑器,官网地址为:http://ueditor.baidu.com/website/download.html ...

  4. UVa 11292 The Dragon of Loowater 【贪心】

    题意:有一条有n个头的恶龙,有m个骑士去砍掉它们的头,每个骑士可以砍直径不超过x的头,问怎样雇佣骑士,使花的钱最少 把头的直径从小到大排序,骑士的能力值也从小到大排序,再一个一个地去砍头 #inclu ...

  5. ONGUI->NGUI->UGUI (Unity UI史)

    各GUI的介绍 ONGUI:Unity自带的绘制界面工具,它的成像原理是基于表层的,所以执行效率非常的低,并且没有提供复杂的UI的接口,就算开发者硬着头皮写上去只能让UI的执行效率更低. NGUI:第 ...

  6. Jetty初探

    一.在jetty中部署web应用 Jetty 和 Tomcat 一样都是一个web server的container, 用户可以在里面 deploy 自己的 war 包,然后启动 Jetty, 进而通 ...

  7. python 用法测试

    Python 3.5.6 1.js风格的回调测试 def b(): ') def a(fn): if callable(fn): fn() a(b) class Sample: def q(self) ...

  8. 通过页面预加载(preload)提升小程序的响应速度

    GitHub: https://github.com/WozHuang/mp-extend 主要目标 如果小程序在打开新页面时需要通过网络请求从接口中获取所用的数据,在请求完成之前页面都会因为没有数据 ...

  9. php字符处理

    1.strstr 截取某个字符后的字符: echo strstr("123456789","5");//输出:6789

  10. 如何设置,获取,删除cookie?

    cookie : 存储数据,当用户访问了某个网站(网页)的时候,我们就可以通过cookie来像访问者电脑上存储数据 1.不同的浏览器存放的cookie位置不一样,也是不能通用的 2.cookie的存储 ...