FatMouse's Speed

HDOJ-1160

注意输出长度的时候不是输出dp[n]

#include<bits/stdc++.h>
using namespace std;
const int maxn=1003;
const int INF=0X3F3F3F3F;
int w[maxn];//weight
int s[maxn];//speed
int dp[maxn];//dp[i]表示以i结尾的最长上升子序列的长度
struct node{
int weight;
int speed;
int num;
bool operator<(const node& t)const{
if(weight<t.weight&&speed>t.speed){
return true;
}else{
return false;
}
}
};
bool cmp(const node&a,const node& b){
if(a.weight==b.weight){
return a.speed>b.speed;
}else return a.weight<b.weight;
}
node mice[maxn];
int father[maxn];
int main(){
int n=0;
int i=1;
while(cin>>w[i]>>s[i]){
mice[i]=node{w[i],s[i],i};
i++;
n++;
}
memset(dp,-INF,sizeof(dp));
sort(mice+1,mice+n+1,cmp);
memset(father,-1,sizeof(father));
for(i=1;i<=n;i++){
dp[i]=1;
for(int j=1;j<i;j++){
if(mice[j]<mice[i]){
if(dp[j]+1>dp[i]){
dp[i]=dp[j]+1;
father[i]=j;
}
}
}
}
int maxs=-INF;
int maxi=0;
for(i=1;i<=n;i++){
//cout<<dp[i]<<endl;
if(dp[i]>maxs){//没有等于
maxs=dp[i];
maxi=i;
}
}
cout<<maxs<<endl;//注意这里不是直接输出dp[n],因为dp[i]表示以i结尾的子序列的最大长度,但这可能不是最终答案的最大长度。
i=maxi;
vector<int> v;
for(;i!=-1;i=father[i]){
v.push_back(mice[i].num);
//cout<<mice[i].num<<endl;
}
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++){
cout<<v[i]<<endl;
}
//system("pause");
return 0;
}

HDOJ-1160(最长上升子序列变形)的更多相关文章

  1. HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

  2. hdu1503 最长公共子序列变形

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...

  3. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  4. HOJ Recoup Traveling Expenses(最长递减子序列变形)

    A person wants to travel around some places. The welfare in his company can cover some of the airfar ...

  5. hdu 1080 dp(最长公共子序列变形)

    题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G -  G ...

  6. uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)

    题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...

  7. POJ 2250(最长公共子序列 变形)

    Description In a few months the European Currency Union will become a reality. However, to join the ...

  8. poj1836--Alignment(dp,最长上升子序列变形)

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13319   Accepted: 4282 Descri ...

  9. hdu1243(最长公共子序列变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1243 分析:dp[i][j]表示前i个子弹去炸前j个恐怖分子得到的最大分.其实就是最长公共子序列加每个 ...

  10. 洛谷 P1020 导弹拦截(dp+最长上升子序列变形)

    传送门:Problem 1020 https://www.cnblogs.com/violet-acmer/p/9852294.html 讲解此题前,先谈谈何为最长上升子序列,以及求法: 一.相关概念 ...

随机推荐

  1. 【bzoj 3433】{Usaco2014 Jan} Recording the Moolympics(算法效率--贪心)

    题意:给出n个区间[a,b),有2个记录器,每个记录器中存放的区间不能重叠.求2个记录器中最多可放多少个区间. 解法:贪心.只有1个记录器的做法详见--关于贪心算法的经典问题(算法效率 or 动态规划 ...

  2. Codeforces Round #636div3 D. Constant Palindrome Sum (划分区间,差分)

    题意:给你一个长度为偶数n的数组,每次可以将一个元素修改为不大于k的值,要求每个a[i]+a[n-i+1]都相等,求最少操作多少次 题解:假设每一对的和都为sum,小的记为mn,大的记为mx;     ...

  3. SQL 计算表A字段在表B字段中出现的次数

    SELECT A.Id,A.Name,COUNT(B.LiveID) AS count from SetLiveHistory B RIGHT JOIN Live A ON B.LiveId=A.Id ...

  4. C# TCP应用编程三 异步TCP应用编程

    利用TcpListener和TcpClient类在同步方式下接收.发送数据以及监听客户端连接时,在操作没有完成之前一直处于阻塞状态,这对于接受.发送数据量不大的情况或者操作勇士较短的情况下是比较方便的 ...

  5. 谈到云原生, 绕不开"容器化"

    传送门 什么是云原生? 云原生设计理念 .NET微服务 Containers 现在谈到云原生, 绕不开"容器". 在<Cloud Native Patterns>一书中 ...

  6. k8s-3-容器云监控系统

    apollo小结 课程目录 一.容器云监控prometheus概述 https://prometheus.io/docs/introduction/overview/ #官方文档 https://gi ...

  7. 在程序中通过Process启动外部exe的方法及注意事项

    启动外部进程的方法: /// <summary> /// 启动外部进程 /// </summary> /// <param name="path"&g ...

  8. spring再学习之AOP准备

    一.aop思想: 横向重复,纵向抽取 1.乱码 2.事务管理 3,action 二.spring能够为容器中管理的对象生成代理对象 1.spring能帮我们生成代理对象 2.spring实现aop的原 ...

  9. codeforces 5E(非原创)

    E. Bindian Signalizing time limit per test 4 seconds memory limit per test 256 megabytes input stand ...

  10. 翻译:《实用的Python编程》01_05_Lists

    目录 | 上一节 (1.4 字符串) | 下一节 (1.6 文件) 1.5 列表 本节介绍 Python 原始数据类型列表(list). 列表是一种有序的集合. 创建列表 使用方括号 [] 来定义列表 ...