怒刷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 ...
随机推荐
- setTimeout setInterval 区别 javascript线程解释
原文:http://www.iamued.com/qianduan/1645.html 今天看到这篇文章,学到了不少东西 特此发出来 和大家分享 JavaScript的setTimeout与setIn ...
- ASP.NET MVC 修改视图的默认路径(MVC2,MVC3)
ASP.NET MVC2 修改视图的默认路径 步骤:1.编写继承自WebFormViewEngine的类,重写视图路径 2.在Application_Start()中添加语句: ViewEngines ...
- (剑指Offer)面试题19:二叉树的镜像
题目: 操作给定的二叉树,将其变换为源二叉树的镜像. 二叉树的定义如下: struct TreeNode{ int val; TreeNode* left; TreeNode* right; }; 输 ...
- java静态代理与动态代理简单分析
原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/5860749.html 1.动态代理(Dynamic Proxy) 代理分为静态代理和动态代理 ...
- addClass 函数
javascript: function addClass(id,new_class){ var i,n=0; new_class=new_class.split(","); fo ...
- Javascript如何访问和处理系统文件
一.功能实现核心:FileSystemObject 对象 要在javascript中实现文件操作功能,主要就是依靠FileSystemobject对象. 二.FileSystemObject编程 使用 ...
- 一分钟制作U盘版BT3 - 有图滴儿 bt3破解教程
一分钟制作 BT3 U盘版方便,快捷简单无效不退款 光盘版BT3, 大概694MB,直接刻盘,然后用光盘引导,就可以进入bt3,连接为:http://ftp.heanet.ie/mirrors/bac ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
- 【KPC】关于为什么不用Zepto而用JQuery
1.zepto在window phone手机上不是很兼容 2.JQuery的Deferred对象在zepto上不支持. 3.JQuery经过压缩,以及部分页面的使用,以及缓存,可以达到优化用户体验的效 ...
- Cocos2d-x 程序是如何开始运行与结束的
题记:对于技术,我们大可不必挖得那么深,但一定要具备可以挖得很深的能力 问题的由来 怎么样使用 Cocos2d-x 快速开发游戏,方法很简单,你可以看看其自带的例程,或者从网上搜索教程,运行起 ...