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. ci 在阿里云访问的时候404

    最近想把ci 弄到阿里云去,结果发现,本地好好的,到了阿里云就404了.网上查了下 原来是 配置文件的问题. 配置文件就是 vhost下面的 **.conf文件  要有这个才行 location / ...

  2. 迭代器概念与traits编程技法

    //迭代器是一种smart pointer template<typename T> class ListItem { public: T value() const { return _ ...

  3. access-list/eigrp等 反掩码计算

    access-list/eigrp等 反掩码计算 原则:地址部分,相同的照写,不同的写"0"     反掩码部分,相同的写"0",不同的写"1&quo ...

  4. uva 10716 Evil Straw Warts Live(贪心回文串)

    这道题目我用了一上午才做出来,还是看的别人的思路,尽管没有看代码做的有点慢.代码能力还是得加强啊.思维 得缜密.不能想当然,要有根据,写上的代码要有精确度.省的以后还得慢慢调试 思路:贪心.每次都查看 ...

  5. python-pexpect_01安装

    一:python2.7.12安装   #获取python2.7.12 wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz   ...

  6. python hehe

    键盘监听事件 标签: 键盘监听python 2016-08-22 14:36 226人阅读 评论(0) 收藏 举报  分类: 其他(33)  本文以一段简单的监听鼠标.键盘事件的程序,实现获取用户的输 ...

  7. web的自己主动化公布

    </pre>基于眼下业务的版本号.使用的maven 及tomcat <p></p><p>假设我们使用 Jenkins 公布是比較好的,可是存在一定的问题 ...

  8. Android离线语音识别(PocketSphinx)

    近期做项目.用到离线语音识别.整了好久,查了好多方法.最终完毕.网上资料有点乱,并且大部分就是那几个人写的.一群人转!以下我总结一下.也为后来人行个方便. 关于环境配置我就不多说了.我就是依照这个教程 ...

  9. Coursera Algorithms Programming Assignment 5: Kd-Trees (98分)

    题目地址:http://coursera.cs.princeton.edu/algs4/assignments/kdtree.html 分析: Brute-force implementation. ...

  10. aixcoder智能编程助手开发插件推荐

    1. aixcoder安装使用 1.1. 介绍 1.1.1. 功能 智能代码提示她用强大的深度学习引擎,能给出更加精确的代码提示: 代码风格检查她有代码风格智能检查能力,帮助开发者改善代码质量: 编程 ...