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. 【sql技巧】mysql修改时,动态指定要修改的字段 update `table` set (case when ....) = 1 where id = xx

    如果你点进了这篇帖子,那么你一定遇到了跟我一样的问题.别看题目的set case when...,我一开始也是第一反应是用case when但是发现并不好使. 问题呢,说得高大上一点:动态指定要修改的 ...

  2. vijos - P1122出栈序列统计 (卡特兰数)

    P1122出栈序列统计 未递交 标签:NOIP普及组2003[显示标签] 描写叙述 栈是经常使用的一种数据结构,有n令元素在栈顶端一側等待进栈,栈顶端还有一側是出栈序列. 你已经知道栈的操作有两·种: ...

  3. Open Flash Chart2 常用的参数

    http://fyzeng.diandian.com/post/2011-07-29/3339982 {   /* 图表标题 */   "title" : {     " ...

  4. Java 注解入门实例 &amp;&amp; 注解传參

    參考 概念:java提供了一种原程序中的元素关联不论什么信息和不论什么元数据的途径和方法 JDK内置系统注解: @Override 用于修饰此方法覆盖了父类的方法; @Deprecated 用于修饰已 ...

  5. 使用CDN

    CDN的全称是Content Delivery Network.中文直译过来是:内容交付网络. 它的主要意思是,将某些内容进行交付的网络.对于站点开发而言,我们所讲的内容通常指的是内容文件(比如jav ...

  6. QT如何修改编程语言的字体

    工具-选项,然后在文本编辑器中设置要的字体

  7. oc 和swift混编的时候打包ipa安装不了

    做了一个oc项目.里面实用到swift第三方,真机执行的时候是正常的,用企业级证书打包成ipa之后安装完毕之后闪退.通过导出手机log日志发现错误提示: Dyld Error Message:   L ...

  8. 李洪强经典面试题31- FMDB

    n什么是FMDB pFMDB是iOS平台的SQLite数据库框架 pFMDB以OC的方式封装了SQLite的C语言API p nFMDB的优点 p使用起来更加面向对象,省去了很多麻烦.冗余的C语言代码 ...

  9. CentOS 7下安装Hadoop2.2

    这里就介绍CentOS的安装了,直接进入Hadoop2.2伪分布模式安装. 1.安装包下载 1.1.下载JDK1.7 眼下JDK的版本号是jdk1.8.0_25.这里下载的是jdk1.7.0_67. ...

  10. npm/bower/brew

    npm: npm(node package manager)node包管理器,用来下载发布第三方工具包,例如:代码的压缩.合并.编译的插件包.主要功能:安装.卸载.更新.查看.搜索.发布等 npm的具 ...