HDU_1160_FatMouse's Speed_dp
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
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.
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.
#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的更多相关文章
随机推荐
- MyBatis3教程
MyBatis3教程: http://www.yihaomen.com/article/java/302.htm http://www.mybatis.org/mybatis-3/zh/index.h ...
- RMAN RECOVERY
Data Recovery Advisor The health monitor and the ADR The capabilities and limitations of DRA using t ...
- ubuntu update时发生错误
The following packages have been kept back解决方案Ubuntu和Debian下更新软件包,在运行 sudo apt-get upgrade 有时会看到如下提示 ...
- Oracle Study之--Oracle 11gR2通过RMAN克隆数据库
Oracle Study之--Oracle 11gR2通过RMAN克隆数据库 Purpose of Database Duplication A duplicate database is usefu ...
- 【UML 建模】在线UML建模工具 ProcessOn 使用具体解释
总结 : -- 推荐理由 : 近期从 Windows 操作系统 转到 MAC 上, 正在看设计模式 和 重构, 找不到好用的 UML 工具, 因此在网上找了一款能够在线使用的 UML 工具, 用起来发 ...
- hdu 1671 Phone List 字典树
// hdu 1671 Phone List 字典树 // // 题目大意: // // 有一些电话号码的字符串长度最多是10,问是否存在字符串是其它字符串的前缀 // // // 解题思路: // ...
- 查找两个大文件(1G以上)的相同内容PHP版
这是是一个大文件处理,面试官出题的意图并不希望你两层for循环进行遍历,这种答案肯定是不会要的! 这道题目的解法思路是: 顺序读取两个文件的的全部记录 将每条记录经过hash->转换为10进制- ...
- win32 API函数
cozy的博文 win32 API函数大全 (2008-03-15 16:28) 分类: 个人日记 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WN ...
- Quartz.net使用入门(三)
Windows服务,自定义安装,卸载服务+Quartz.net app.config配置文件 <?xml version="1.0"?> <configurati ...
- CF36 E Two Paths——欧拉(回)路
题目:http://codeforces.com/contest/36/problem/E 给定一张无向图,要求输出两条欧拉路覆盖所有边: 分类讨论,首先判-1:有两个以上连通块 / 有四个以上奇度数 ...