FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13133    Accepted Submission(s): 5778
Special Judge

Problem Description
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
 
Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.

The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.

Two mice may have the same weight, the same speed, or even the same weight and speed.

 
Output
Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that

W[m[1]] < W[m[2]] < ... < W[m[n]]

and

S[m[1]] > S[m[2]] > ... > S[m[n]]

In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one. 

 
Sample Input

6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900

 
Sample Output
4
4
5
9
7
最长下降子序列,t数组记录下边,输出序列下表
 #include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max 10005
int dp[Max],t[Max],ans[Max];
struct node
{
int s,w,n;
}a[Max];
bool cmp(node x,node y)
{
return x.w<y.w;
}
int main()
{
int num;
int i=,j;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&a[i].w,&a[i].s)!=EOF)
{
a[i].n=i;
i++;
}
num=i-;
sort(a+,a+num+,cmp);
/* for(i=1;i<=num;i++)
{
cout<<a[i].w<<" "<<a[i].s<<" "<<a[i].n<<endl;
}*/
for(i=;i<Max;i++)
{
dp[i]=;
t[i]=;
}
for(i=;i<=num;i++)
{
for(j=;j<i;j++)
{
if(a[i].s<a[j].s&&a[i].w!=a[j].w&&(dp[j]+)>dp[i])
{
dp[i]=dp[j]+;
t[i]=j;
}
}
}
int maxn=dp[num],index=num;
for(i=;i<=num;i++)
if(dp[i]>maxn)
{
index=i;
maxn=dp[i];
}
ans[maxn]=a[index].n;
// cout<<ans[maxn]<<endl;
index=t[index];
for(i=maxn-;i>=;i--)
{
ans[i]=a[index].n;
// cout<<ans[i]<<endl;
index=t[index];
}
cout<<maxn<<endl;
for(i=;i<=maxn;i++)
cout<<ans[i]<<endl;
}
 

FatMouse's Speed(HDU LIS)的更多相关文章

  1. FatMouse's Speed (hdu 1160)

          #include <iostream> #include <cstdio> #include <cstring> #include <algori ...

  2. 动态规划----FatMouse’s Speed(HDU 1160)

    参考:https://blog.csdn.net/u012655441/article/details/64920825 https://blog.csdn.net/wy19910326/articl ...

  3. FatMouse's Speed ~(基础DP)打印路径的上升子序列

    FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take ...

  4. (记忆化搜索) FatMouse and Cheese(hdu 1078)

    题目大意:   给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值   (题目很容 ...

  5. 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)

    //1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...

  6. 2021.12.06 P2501 [HAOI2006]数字序列(动态规划+LIS)

    2021.12.06 P2501 [HAOI2006]数字序列(动态规划+LIS) https://www.luogu.com.cn/problem/P2501 题意: 现在我们有一个长度为 n 的整 ...

  7. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  8. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. HDU 1160:FatMouse's Speed(LIS+记录路径)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. Linux 的系统运行级别

    运行级别          说明 0          系统关机状态 1 单用户工作状态,用于root对系统进行维护,此时不予许其他用户使用主机.(类似于windows 的安全模式) 2       ...

  2. Java抽象类深入理解-----模板方法设计模式(Templete Method)

    模板方法设计模式(Templete Method) 定义一个操作中的算法骨架,而将一些可变部分的实现延迟到子类中. 模板方法设计模式使得子类可以不改变一个算法的结构即可重新定义该算法某些特定的步骤. ...

  3. Android中图片的目录

    图片放在hdpi及在mdpi中的效果是不一样的 http://blog.csdn.net/loongggdroid/article/details/9469935

  4. jQuery Ajax 实例 ($.ajax、$.post、$.get)转

    Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作,不用考虑浏览器的诧异了. 推荐一篇不错的jQuery Ajax 实例文章,忘记了可以去看看,地址为:ht ...

  5. syslog-ng-3.5.6把容器的单核cpu跑满

    Question 最近,偶然,会有人说,其docker容器中syslog-ng把cpu跑满,使用perf,mpstat,strace工具看到是syslog-ng在内核态cpu使用率很高,怀疑是某个系统 ...

  6. WPF页面切换及弹窗

    WPF页面切换及弹窗 结构如图: 效果如图: 代码如下: xaml <Window x:Class="PageChange.MainWindow" xmlns="h ...

  7. 2个2D向量计算交点的夹角和补角

    2维向量如何计算与某一个交点之间的夹角,假设A,B是向量,C是他们共同连接的一个点计算出A-C-B形成的角度   我们先了解几个简单的计算: 2D向量的乘积计算 (A.x * B.x + A.y * ...

  8. pyqt 正则表达式例子学习

    def rex01(self): username=QtCore.QRegExp('[a-zA-Z0-9_]{2,10}') self.names.setValidator(QtGui.QRegExp ...

  9. [CSS3] CSS Display Property: Block, Inline-Block, and Inline

    Understanding the most common CSS display types of block, inline-block, and inline will allow you to ...

  10. Android窗口管理服务WindowManagerService显示窗口动画的原理分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8611754 在前一文中,我们分析了Activi ...