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. MyBatis3教程

    MyBatis3教程: http://www.yihaomen.com/article/java/302.htm http://www.mybatis.org/mybatis-3/zh/index.h ...

  2. RMAN RECOVERY

    Data Recovery Advisor The health monitor and the ADR The capabilities and limitations of DRA using t ...

  3. ubuntu update时发生错误

    The following packages have been kept back解决方案Ubuntu和Debian下更新软件包,在运行 sudo apt-get upgrade 有时会看到如下提示 ...

  4. Oracle Study之--Oracle 11gR2通过RMAN克隆数据库

    Oracle Study之--Oracle 11gR2通过RMAN克隆数据库 Purpose of Database Duplication A duplicate database is usefu ...

  5. 【UML 建模】在线UML建模工具 ProcessOn 使用具体解释

    总结 : -- 推荐理由 : 近期从 Windows 操作系统 转到 MAC 上, 正在看设计模式 和 重构, 找不到好用的 UML 工具, 因此在网上找了一款能够在线使用的 UML 工具, 用起来发 ...

  6. hdu 1671 Phone List 字典树

    // hdu 1671 Phone List 字典树 // // 题目大意: // // 有一些电话号码的字符串长度最多是10,问是否存在字符串是其它字符串的前缀 // // // 解题思路: // ...

  7. 查找两个大文件(1G以上)的相同内容PHP版

    这是是一个大文件处理,面试官出题的意图并不希望你两层for循环进行遍历,这种答案肯定是不会要的! 这道题目的解法思路是: 顺序读取两个文件的的全部记录 将每条记录经过hash->转换为10进制- ...

  8. win32 API函数

    cozy的博文 win32 API函数大全   (2008-03-15 16:28) 分类: 个人日记 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WN ...

  9. Quartz.net使用入门(三)

    Windows服务,自定义安装,卸载服务+Quartz.net app.config配置文件 <?xml version="1.0"?> <configurati ...

  10. CF36 E Two Paths——欧拉(回)路

    题目:http://codeforces.com/contest/36/problem/E 给定一张无向图,要求输出两条欧拉路覆盖所有边: 分类讨论,首先判-1:有两个以上连通块 / 有四个以上奇度数 ...