FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13894    Accepted Submission(s): 6133
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
 
题目不难,但是输入让我很不舒服,输入到文件末尾再处理,所以自己看不到运行结果。。。wa了无数次。。。
大意是:找一个最长的子序列,满足weight增加,speed减小。
状态转移:if(w[i]>w[i]&&spe[i]<spe[j]) dp[i]=max(dp[i]dp[j]+1);
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 99999999
struct Node
{
int num;
int weight;
int speed;
} mouse[]; int dp[];
int father[]; bool cmp(Node a,Node b)
{
if(a.weight<b.weight)
return ;
else if(a.weight==b.weight&&a.speed>b.speed)
return ;
return ;
}
/*
void find(int j)
{
if(father[j]==j)
{
cout<<mouse[j].num<<endl;
return;
}
if(father[j]!=j)
{
find(father[j]);
cout<<mouse[j].num<<endl;
}
}
*/
int main()
{
int cnt=;
while(scanf("%d%d",&mouse[cnt].weight,&mouse[cnt].speed)!=EOF)
{
mouse[cnt].num=cnt;
dp[cnt]=;
father[cnt]=cnt;
cnt++;
}
sort(mouse+,mouse+cnt,cmp);
for(int i=; i<=cnt-; i++)
for(int j=; j<i; j++)
{
if(mouse[i].weight>mouse[j].weight&&mouse[i].speed<mouse[j].speed&&dp[j]+>dp[i])
{
dp[i]=dp[j]+;
father[i]=j;
}
}
int flag;
int ans=;
for(int i=;i<=cnt-;i++)
if(dp[i]>ans)
{
ans=dp[i];
flag=i;
}
printf("%d\n",ans);
int num[];
for(int i=;i<=ans;i++)
{
num[i]=mouse[flag].num;
flag=father[flag];
}
for(int i=ans;i>=;i--)
printf("%d\n",num[i]);
return ;
}

HDU_1160_FatMouse's Speed_dp的更多相关文章

随机推荐

  1. Ubuntu 16.04安装FTP客户端filezilla

    1.安装: sudo apt-get install filezilla 参考: http://os.51cto.com/art/201103/247564.htm

  2. SiteMesh2-sitemesh.xml的其它映射器的用法

    在sitemesh.xml中做常用的三个映射器,总结如下: 映射器元素的顺序确定优先级.良好的应用程序应使用以下顺序, Parameter query = ParameterDecoratorMapp ...

  3. 第K顺序统计量的求解

    一个n个元素组成的集合中,第K个顺序统计量(Order Statistic)指的是该集合中第K小的元素,我们要讨论的是如何在线性时间(linear time)里找出一个数组的第K个顺序统计量. 一.问 ...

  4. iOS常用的正则表达式总结

    /* 正则表达式说明: . 匹配除换行符以外的任意字符 \\w 匹配字母或数字或下划线或汉字 \\s 匹配任意的空白符 \\d 匹配数字 \\b 匹配单词的开始或结束 ^ 匹配字符串的开始 $ 匹配字 ...

  5. starUML 2.5.1 for mac

    http://www.macupdate.com/app/mac/55571/staruml/download 一直在windows下使用 star UML,占用资源少,简洁易用. Mac下也能够用了 ...

  6. 【转】linux 远程桌面工具NX

    1.在linux服务器上需要安装3个文件,下载地址为: http://www.nomachine.com/download-package.php?Prod_Id=1977 nxclient-3.4. ...

  7. Java进程堆外内存(off heap)大小

    一.使用ByteBuffer.allocateDirect分配的off heap内存大小 本机进程 在Jvisualvm中安装 Mbeans插件.然后查看java.nio/BufferPool/dir ...

  8. LeetCode 690. Employee Importance (职员的重要值)

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  9. java基础--自我总结

    1.带小数点数字默认为double类型,double范围比float大,为了不损失精度,double类型不会自动转换成float类型: 例:float f = 1.0f      //必须这么写 2. ...

  10. 万维网 WWW (World Wide Web)

    万维网 WWW (World Wide Web)并非某种特殊的计算机网络.万维网是一个大规模的.联机式的信息储藏所.万维网用链接的方法能非常方便地从因特网上的一个站点访问另一个站点,从而主动地按需获取 ...