G - FatMouse's Speed

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description:

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
 
 
正常一个·变量的求法变为结构体封装,,,,,,额外加一个pre数组记录回溯路径
1A~~~~
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
struct node{
int weight,speed,id;
}que[maxn];
int dp[maxn],pre[maxn];
bool cmp(struct node t1,struct node t2){
if(t1.weight!=t2.weight)
return t1.weight<t2.weight;
return t1.speed>t2.speed;
} int main(){
int x,y;
int tot;
tot=;
while(scanf("%d%d",&que[tot].weight,&que[tot].speed)!=EOF){
que[tot].id=tot;
tot++;
}
sort(que+,que+tot+,cmp);
memset(dp,,sizeof(dp));
memset(pre,-,sizeof(pre));
dp[]=;
for(int i=;i<tot;i++){
dp[i]=;
for(int j=i-;j>=;j--){
if((que[i].weight>que[j].weight)&&(que[i].speed<que[j].speed)&&dp[i]<dp[j]+){
dp[i]=dp[j]+;
pre[i]=j;
}
}
}
int point,ans=-;
for(int i=;i<tot;i++){
if(dp[i]>ans){
ans=dp[i];
point=i;
}
}
printf("%d\n",ans);
int tmp[maxn];
int cnt=;
for(int i=point;i!=-;i=pre[i]){
// printf("%d\n",que[i].id);
tmp[cnt++]=que[i].id;
}
for(int i=cnt-;i>=;i--)
printf("%d\n",tmp[i]); return ;
}

HDU 1160 DP最长子序列的更多相关文章

  1. FatMouse's Speed HDU - 1160 最长上升序列, 线性DP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usi ...

  2. ZOJ 1108 FatMouse's Speed (HDU 1160) DP

    传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...

  3. HDU 1069&&HDU 1087 (DP 最长序列之和)

    H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  4. HDU 4604 Deque 最长子序列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 Deque Time Limit: 4000/2000 MS (Java/Others)     ...

  5. HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)

    题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...

  6. HDU 1513 最长子序列

    Palindrome Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  8. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  9. 最长子序列dp poj2479 题解

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 44476   Accepted: 13796 Des ...

随机推荐

  1. 横竖屏切换时,Activity的生命周期

    横竖屏切换时,Activity的生命周期 1.新建一个Activity,并把各个生命周期打印出来 2.运行Activity,得到如下信息 onCreate-->onStart-->onRe ...

  2. Flash Decompiler

    http://www.sothink.com/product/flash-decompiler-for-mac/ http://blog.sina.com.cn/s/blog_697935ad0100 ...

  3. 字符串哈希函数(String Hash Functions)

    哈希函数举例 http://www.cse.yorku.ca/~oz/hash.html Node.js使用的哈希函数 https://www.npmjs.org/package/string-has ...

  4. live555编译、移植

    1.windows下编译 转 http://www.cnblogs.com/skyseraph/archive/2012/04/11/2442840.html 2.linux下编译,以及交叉编译,海思 ...

  5. Linux下MySQL忘记密码

    系统:CentOS6.6 64位 参考文档(截图请看原网址): Linux下MySQL忘记root密码怎么办_百度经验 http://jingyan.baidu.com/article/1709ad8 ...

  6. jquery插件写法

    //传统写法 //全局方法 ;(function($){ $.method = function(){ } //or $.obj = { method1:function(){}, method2:f ...

  7. YII2数据库依赖缓存

    首先配置一下缓存,自己选择是用文件缓存还是数据库缓存等. 'cache' => [ 'class' => 'yii\caching\FileCache', ], 然后就可以通过 Yii:: ...

  8. ngrok内网穿透利器在windws下的使用

    1.到官网下载windows版本:https://ngrok.com/download 2.解压,双击“ngrok.exe” 3.输入“ngrok http 80”,会随机给你分配域名.见下图. ng ...

  9. C#中返回值封装

    在平时开发过程中常常需要取一个方法的返回值,BOSS写了一个返回值类,做个练习以备不时之需: 返回值支持泛型和非泛型 先贴上代码: 非泛型返回值类: using System; using Syste ...

  10. JAVA利用Zip4j解压缩【转】

    官方地址:http://www.lingala.net/zip4j/(需要FQ) jar包:http://pan.baidu.com/s/145hwI 演示包:http://pan.baidu.com ...