【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed
https://vjudge.net/contest/68966#problem/J
【Accepted】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm> using namespace std;
const int maxn=1e3+;
struct node
{
int w;
int s;
int id;
}a[maxn];
int pre[maxn];
int dp[maxn];
bool cmp(node x,node y)
{
return x.w<y.w;
} void Print(int pos)
{
if(pos==-) return;
Print(pre[pos]);
printf("%d\n",a[pos].id);
}
int main()
{
int cnt=;
while(scanf("%d%d",&a[cnt].w,&a[cnt].s)!=EOF)
{
a[cnt].id=cnt+;
cnt++;
}
sort(a,a+cnt,cmp);
memset(pre,-,sizeof(pre));
fill(dp,dp+cnt,);
for(int i=;i<cnt;i++)
{
for(int j=;j<i;j++)
{
if(a[j].w<a[i].w&&a[j].s>a[i].s)
{
if(dp[j]+>dp[i])
{
dp[i]=dp[j]+;
pre[i]=j;
}
}
}
}
int cou=;
int pos=-;
for(int i=;i<cnt;i++)
{
if(dp[i]>cou)
{
cou=dp[i];
pos=i;
}
}
if(cou==)
{
printf("%d %d\n",,);
return ;
}
cout<<cou<<endl;
Print(pos);
return ;
}
【教训】
while(scanf("%d%d",&a[cnt].w,&a[cnt].s)!=EOF)
{
a[cnt].id=++cnt;
}
是不对的,先算++cnt,前面的cnt已经加一了
【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed的更多相关文章
- HDU - 1503 最长公共子序列记录路径
题意:先给两个水果的名字然后得出一个最短的序列包含这两个词. 思路:我一开始的思路是先求出最长公共子序列,然后做一些处理将其他的部分输出来:两种水果的字符串和最长公共子序列的字符串这三个字符串做对比, ...
- HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- F - LCS 题解(最长公共子序列记录路径)
题目链接 题目大意 给你两个字符串,任意写出一个最长公共子序列 字符串长度小于3e3 题目思路 就是一个记录路径有一点要注意 找了好久的bug 不能直接\(dp[i][j]=dp[i-1][j-1]+ ...
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
随机推荐
- lock和synchronized的同步区别与选择
1. lock是一个接口,而synchronized是java的一个关键字,synchronized是内置的语言实现:(具体实现上的区别在<Java虚拟机>中有讲解底层的CAS不同,以前有 ...
- AJPFX总结Collection集合(下)
List集合特有方法 特有方法.凡是可以操作角标的方法都是该体系特有的方法. 增 add(index,element);在指定位置添加元素 addAll(index ...
- poj2441 Arrange the Bulls
思路: 状态压缩dp.需要一点优化,否则容易超时. 实现: #include <cstdio> #include <vector> #include <cstring&g ...
- IP地址 子网掩码 默认网关和DNS服务器的关系
在过去,男人是需要能够上房揭瓦的,是要能够修水管的.现在的男人是需要会装系统的,会设置路由器的.世界变化太快! 废话不多说,本文来讨论一下电脑上最为常见的几个网络参数:IP地址.子网掩码.默认网关和D ...
- 入门Promise的用法
new Promise(function(resolve,reject){ resolve(); //数据处理完成 reject(); //数据处理出错 }).then(function A(){ / ...
- Navicat工具备份还原mysql数据库详细图解
Navicat是个很不错的MYSQL数据库管理工具,我们常用的还web形式的phpmyadmin和font这三种了,都是非常不错的mysql管理工具.因为Navicat工具兼容性比较好,操作也比较简单 ...
- 语音行业技术领先者Nuance诚招ASR/NLP研发工程师和软件工程师
Nuance is a leading provider of voice and language solutions for businesses and consumers around the ...
- c++ vector容器遍历方式
#include <vector> #include <iostream> class Test { public: int a; int b; int c; Test() { ...
- log4j.xml 精选的log4j.xml文档,比较详细,网上的版本很多,这个版本相对而言比较完整
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration PUB ...
- vue在传值的时候经常遇到的问题
在我用vue编写程序的时候,在传值的时候,经常会遇到些问题,像今天遇到了两个问题,在用父传子的方法去传值,当父组件中的要传的数据是for循环出来的或者是列表的时候,你想每次运行的事件,都去传某一行,或 ...