hdu 1257/1800 - 贪心,dp
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的更多相关文章
- hdu 5037 Frog 贪心 dp
哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog ...
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 【贪心】HDU 1257
HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...
- 怒刷DP之 HDU 1257
最少拦截系统 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 ...
- HDU 1257——最少拦截系统——————【LIS变型题】
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 1257 最少拦截系统 最长递增子序列
HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...
随机推荐
- Ubuntu 14.04安装Skype
Skype 4.3版本在14.04 LTS工作正常.安装步骤: $ sudo apt-get remove skype skype-bin:i386 skype:i386 $ sudo apt-get ...
- struts2学习之基础笔记8
文件的上传和下载 上传 步骤1:在文件上传表单中设置method和enctype属性值 格式:<s:form method=”post” enctype =”multipart/ form.da ...
- VSCode新建vue文件自定义模板
在一个Vue的项目中,反复的新建.vue文件是一个必不可少的工序.本着科技让人偷懒的原则,我们可以利用VSCode的snippet在.vue文件创建后能轻松地生成一套模板. 整个过程是轻松加愉快的,只 ...
- 什么是 Dropout
为了应对神经网络很容易过拟合的问题,2014年 Hinton 提出了一个神器, **Dropout: A Simple Way to Prevent Neural Networks from Over ...
- 常用sql调优《一》
1. 使用索引,避免在索引列上使用计算. 2.用>=替代> <=替代< 3.用UNION替换OR (适用于索引列) 4.用IN来替换OR 或者 用EXISTS替代IN 5 用W ...
- idea--IntelliJ IDEA隐藏不想看到的文件或文件夹
打开IntelliJ IDEA,File -> Settings -> Editor -> File Types 在红框部分加上你想过滤的文件或文件夹名
- luogu P2584 [ZJOI2006]GameZ游戏排名系统 Splay
实在不想调了QAQ... Code: #include <cstdio> #include <algorithm> #include <cstring> #incl ...
- ntp.log日志梳理
[日志]offset 正负 机器A上执行: remote refid st t when poll reach delay offset jitter ======================== ...
- 普通页面使用vue.js心得
在写本文之前要问自己几个问题,来说明为什么要这么做: 为什么在html中使用vue.js? vue.js已经趋于成熟,个人感觉比jquery要好用的多,但是在node环境下使用vue.js不用使用SS ...
- [luogu] P3210 [HNOI2010]取石头游戏(贪心)
P3210 [HNOI2010]取石头游戏 题目描述 A 公司正在举办一个智力双人游戏比赛----取石子游戏,游戏的获胜者将会获得 A 公司提供的丰厚奖金,因此吸引了来自全国各地的许多聪明的选手前来参 ...