怒刷DP之 HDU 1160
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
prayerhgq (2015-07-28)
System Crawler (2015-09-05)
Description
Input
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
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
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
Sample Output
4
5
9
7
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <queue>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <cstring>
- #include <cctype>
- #include <cstdlib>
- #include <cmath>
- #include <ctime>
- #include <climits>
- using namespace std;
- const int SIZE = ;
- struct Node
- {
- int pos;
- int weight,speed;
- int front,num;
- }DP[SIZE];
- bool comp(const Node & r_1,const Node & r_2);
- int main(void)
- {
- int count = ;
- while(scanf("%d%d",&DP[count].weight,&DP[count].speed) != EOF)
- {
- DP[count].pos = count;
- DP[count].num = ;
- count ++;
- }
- sort(DP,DP + count,comp);
- int max = ,max_loc = ;
- for(int i = ;i < count;i ++)
- {
- DP[i].front = i;
- for(int j = ;j < i;j ++)
- if(DP[i].weight > DP[j].weight && DP[i].speed < DP[j].speed)
- if(DP[i].num < DP[j].num)
- {
- DP[i].num = DP[j].num;
- DP[i].front = j;
- if(max < DP[i].num + )
- {
- max = DP[i].num + ;
- max_loc = i;
- }
- }
- DP[i].num ++;
- }
- int temp[SIZE];
- count = ;
- while()
- {
- temp[count] = max_loc;
- if(max_loc == DP[max_loc].front)
- {
- count ++;
- break;
- }
- max_loc = DP[max_loc].front;
- count ++;
- }
- printf("%d\n",max);
- for(int i = count - ;i >= ;i --)
- printf("%d\n",DP[temp[i]].pos + );
- return ;
- }
- bool comp(const Node & r_1,const Node & r_2)
- {
- return r_1.weight < r_2.weight;
- }
怒刷DP之 HDU 1160的更多相关文章
- 怒刷DP之 HDU 1257
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 怒刷DP之 HDU 1260
Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 怒刷DP之 HDU 1176
免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 怒刷DP之 HDU 1087
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- 怒刷DP之 HDU 1069
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 怒刷DP之 HDU 1024
Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 怒刷DP之 HDU 1029
Ignatius and the Princess IV Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d &a ...
- HDU 1160 DP最长子序列
G - FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 网页布局:float与position的区别
网页开发中布局是一个永恒的话题.巧妙的布局会让网页具有良好的适应性和扩展性.css的布局主要涉及两个属性——position和float.它们俩看上去很容易被弄混,可是仔细分析一下,它们的区别还是很明 ...
- Quartz.NET 2.0 学习笔记(1) :Quartz.NET简介
http://www.cnblogs.com/lzrabbit/archive/2012/04/13/2447609.html
- java静态代理与动态代理简单分析
原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/5860749.html 1.动态代理(Dynamic Proxy) 代理分为静态代理和动态代理 ...
- 栈的应用-四则表达式(C#代码实现)
->概念 中缀表达式 9+(3-1)*3+10/2 转换步骤 9 + 9 + ( 9 3 + ( - 9 3 1 + ( - ) 9 3 1 - + 9 3 1 - + * 9 3 1 - 3 ...
- 【C#】工具类-FTP操作封装类FTPHelper
转载:http://blog.csdn.net/gdjlc/article/details/11968477 using System; using System.Collections.Generi ...
- LVS 单独完成--负载均衡
原文地址:http://blog.sina.com.cn/s/blog_5f54f0be0101eyiu.html LVS 是通过 IPVS 模块来实现的.IPVS是LVS集群的核心,主要用于完成用户 ...
- window.location.href的使用方法
http://hljqfl.blog.163.com/blog/static/40931580201122210573364/ 在写ASP.Net程序的时候,我们常常遇到跳转页面的问题,我们常常使用R ...
- 关于javaScript注册事件传递参数的浅析
最近这半年作为一个java 程序员,我写的javaScript代码都快比java代码多了,前段时间是给某银行做一个柜员管控系统,在柜员授权这一块功能上,由于柜员的授权需要考虑各方面的因素,比如机构权限 ...
- 制作Windows的ico图标
也不知道这个方法是不是最好的,有时间再查看其它方法 首先设计出图标,png格式即可. 使用一款软件 IconWorkshop 下载了一个试用版,临时制作够用了 制作步骤如下: 1.打开png图片 2. ...
- Linux文件时间属性
Linux文件时间属性 ...