FatMouse's Speed

Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge

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 Specification

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 Specification

Your program should output a sequence of lines of data; the first line should contain a numbern; the remainingn lines should each contain a single positive integer (each one representing a mouse). If thesen integers arem[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

Output for Sample Input

4
4
5
9
7

天啊,好可耐的老鼠,抱抱。

为达到DP的无后续性,以其中一个为关键词排序,然后最长上升subque。
从后向前不需要倒序输出。从前向后不要忘记倒序输出:
用 数组记录或者递归实现。


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int m,x,y;
struct in{
int w,s,pos,pre,num;
}a[];
int b[];
bool cmp(in a,in b){
return a.w<b.w;
}
void _solve()
{
for(int i=;i<=m;i++){
for(int j=;j<i;j++){
if(a[i].w>a[j].w&&a[i].s<a[j].s)
if(a[i].num<a[j].num+){
a[i].num=a[j].num+;
a[i].pre=j;
}
}
}
int M=,L=;
for(int i=m;i>=;i--)
{
if(a[i].num>M) {
M=a[i].num;
L=i;
}
}
printf("%d\n",M);
int t=;
while(L>){//也可以试试调用递归来倒序输出
b[++t]=a[L].pos;
L=a[L].pre;
}
for(int i=t;i>=;i--) printf("%d\n",b[i]);
return ;
}
int main()
{
while(~scanf("%d%d",&x,&y))
{
a[++m].w=x;
a[m].s=y;
a[m].pos=m;
a[m].num=;
}
sort(a+,a+m+,cmp);
_solve();
return ;
}

 

zoj 1108 FatMouse's Speed 基础dp的更多相关文章

  1. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  2. FatMouse's Speed 基础DP

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. 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 ...

  4. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

  5. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  6. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  7. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  8. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  9. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

随机推荐

  1. Unity相对于Cocos2d-x的比较

    1.unity:Code in C# or js       cocos:(Code in C++) 2.unity:可以让美工.动画.码农在同一个平台上各司其职(一起玩)       cocos:码 ...

  2. Postman几种常用方式

    Postman几种常用方式 1.get请求直接拼URL形式 对于http接口,有get和post两种请求方式,当接口说明中未明确post中入参必须是json串时,均可用url方式请求 参数既可以写到U ...

  3. 201521123006 《Java程序设计》第7周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boo ...

  4. 使用Eclipse Egit与码云管理你的代码

    总体流程: 建立远程仓库 建立本地仓库并与远程仓库关联 将Eclipse中的项目提交到本地仓库并进而push到远程仓库 一. 配置Eclipse EGit 图解Eclipse中安装及配置EGit插件中 ...

  5. 201521123055 《Java程序设计》第3周学习总结

    1. 本章学习总结 2. 书面作业 Q1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; ...

  6. 201521123036 《Java程序设计》第14周学习总结

    本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 书面作业 MySQL数据库基本操作 1.1 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自己的学号.姓名) ...

  7. Java:@Override标签的多态性详解

    Override(重写)是子类与父类的一种多态性体现. Override允许子类改变父类的一些行为. 为什么需要Override:当父类不满足子类的一些要求时我们就需要子类对父类的一些行为进行重写.  ...

  8. 设置文件opendilag、savedilog默认路径和文件类型

    dlgSave1.Filter:='文件.txt|*.txt;|word文件|*.doc,*.docx'; dlgSave1.InitialDir:=GetCurrentDir; //设置为当前路径 ...

  9. Java是如何解析xml文件的(DOM)

    Java解析xml文件 在Java程序中读取xml文件的过程也称为"解析xml文件": 解析的目的: 获取 节点名和节点值 获取 属性名.属性值. 四中解析方式: DOM SAX ...

  10. Python学习笔记012_网络_异常

    1,Python如何访问互联网? url + lib =  urllib >>> # 使用urllib包下的request模块 >>> >>> i ...