FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)   
Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5546    Accepted Submission(s): 2393
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
题目链接:



解题心得:
1、这个题看似很复杂,其实只有几个环节处理好了之后就比较简单了。第一个环节是输入要求,是单组,但是是多组输入,输入到文件结束为止。处理完了输入要求之后是题目要求质量上升但是速度下降。可以按照质量升序排列一下,然后只剩下速度。然后找速度的最长下降子序列。最后还需要记录一下下降的子序列有哪些。
2、最长下降子序列和最长上升子序列一样的,详情看点击打开链接(n^2算法),点击打开链接(nlogn算法)。主要是记录子序列中的元素有哪些。可以直接开一个dp的结构体,结构体中放一个数组,每次状态转移的时候可以将数组中的元素一起转移然后加上当前状态就可以了。
3、这个问题告诉我们不要太过于死板了,状态转移,关于状态的定义不要过于死板了,只要可以跟着转移的都可以是状态,状态转移中可以有很多操作的。





#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
struct mice
{
int w,s;
int pos;
} m[maxn]; struct Dp
{
int num[maxn];
int Num;
} dp[maxn];
bool cmp(mice a,mice b)
{
return a.w<b.w;
}
int main()
{
int t = 1;
int W,S;
while(scanf("%d%d",&W,&S) != EOF)//处理这个题输入的的办法
{
m[t].w = W;
m[t].s = S;
m[t].pos = t;
t++;
} /*
可以输入0 0结束看看自己的输入是否正确
while(scanf("%d%d",&W,&S) && W)//处理这个题输入的的办法
{
m[t].w = W;
m[t].s = S;
m[t].pos = t;
t++;
}
t--;
for(int i=1;i<=t;i++)
printf("%d %d\n",m[i].w,m[i].s); */ t--;//用来记录有多少个元素
int Max = 0;//记录最长的递减子序列
sort(m,m+t,cmp);//拍一下序,cmp函数自己写一下
for(int i=1;i<=t;i++)
{
dp[i].Num = 1;
dp[i].num[1] = m[i].pos;
}
for(int i=1; i<=t; i++)
{
for(int j=0; j<=i; j++)
{
if(m[j].s > m[i].s && m[j].w < m[i].w)
{
if(dp[j].Num+1 > dp[i].Num)//如果符合状态的转移要求
{
for(int k=1;k<=dp[j].Num;k++)//记录状态的数组一起跟着转移
{
dp[i].num[k] = dp[j].num[k];
dp[i].num[k+1] = m[i].pos;//当前状态也要放入
}
dp[i].Num = dp[j].Num + 1;
if(dp[i].Num > Max)
Max = dp[i].Num;
}
}
}
} bool flag = false;
printf("%d\n",Max);
for(int i=1;i<=t;i++)
{
if(dp[i].Num == Max)
{
flag = true;
for(int j=1;j<=dp[i].Num;j++)
{
if(dp[i].num[j]!=0)
printf("%d\n",dp[i].num[j]);
}
break;
}
}
return 0;
}


动态规划:HDU1160-FatMouse's Speed(记录动态规划状态转移过程)的更多相关文章

  1. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

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

  2. HDU1160 FatMouse's Speed —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...

  3. HDU1160:FatMouse's Speed(最长上升子序列,不错的题)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1160 学的东西还是不深入啊,明明会最长上升子序列,可是还是没有A出这题,反而做的一点思路没有,题意就不多说 ...

  4. [HDU1160]FatMouse's Speed

    题目大意:读入一些数(每行读入$w[i],s[i]$为一组数),要求找到一个最长的序列,使得符合$w[m[1]] < w[m[2]] < ... < w[m[n]]$且$s[m[1] ...

  5. 读懂TCP状态转移

    读懂TCP状态转移过程,对理解网络编程颇有帮助,本文将对TCP状态转移过程进行介绍,但各状态(总共11个)含义不在本文介绍的范围,请参考文末的书目列表. TCP状态转换图(state transiti ...

  6. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  7. hdoj1160 FatMouse's Speed 动态规划

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

  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. Unity3D C# 学习List数据类型的使用

    List<T>类是ArrayList 类的泛型等效类. 该类使用大小可按需动态增加的数组实现 泛型的好处: 它为使用 c#语言编写面向对象程序增加了极大的效力和灵活性.不会强行对值类型进行 ...

  2. 1 误删dbf文件造成ORA-01109: 数据库未打开.

    1.cmd-sqlplus /nolog-conn system/pwd as sysdba 2.shutdown immediate; 3.startup mount; 4.alter databa ...

  3. 从零开始的全栈工程师——js篇2.14(表单与计时器)

    一.表单 Form input select textarea type=”radio/checkbox/password/button/text/submit/reset/” 表单的事件 oncha ...

  4. 【干货】JavaScript DOM编程艺术学习笔记7-9

    七.动态创建标记 在文档中不写占位图片和文字代码,在能调用js的情况下动态创建,文档支持性更好. 在原来的addLoadEvent prepareGallery showPic的基础上增加函数prep ...

  5. Android 类似360悬浮窗口实现源码

    当我们在手机上安装360安全卫士时,手机屏幕上时刻都会出现一个小浮动窗口,点击该浮动窗口可跳转到安全卫士的操作界面,而且该浮动窗口不受其他activity的覆盖影响仍然可见(多米音乐也有相关的和主界面 ...

  6. PagedList.Mvc只有一行时不显示分页

    PagedList.Mvc默认总是显示分页,可以通过设置DisplayMode在只有一行时不显示分页 @Html.PagedListPager(Model, page => Url.Action ...

  7. 转 zigbee学习笔记---Channel、PANID、发射功率及其它参数

    现对z-stack里几个网络参数的设置以及如何获取总结一下.信道配置:Zigbee在3个频段定义了27个物理信道:868MHz频段中定义了1个20Kb/s信道,915MHz频段中定义了10个40Kb/ ...

  8. java Vamei快速教程20 GUI

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! GUI(Graphical User Interface)提供了图形化的界面,允许 ...

  9. linux 命令——47 iostat (转)

    Linux系统中的 iostat 是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会 汇报出CPU使用情况 ...

  10. linux 命令——28 tar

    通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大.tar命令可以为linux的 ...