怒刷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 ...
 
随机推荐
- effective c++ (二)
			
条款04:确定对象使用前已先被初始化 1.由于 c part of c++而且初始化可能导致运行期成本,那么就不保证发生初始化:例如arry是c part of c++的部分从而不能保证初始化,而ST ...
 - cocos2d制作动态光晕效果基础——blendFunc
			
转自:http://www.2cto.com/kf/201207/144191.html 最近的项目要求动态光晕的效果. 何谓动态光晕?之前不知道别人怎么称呼这个效果, 不过在我看来,“动态光晕”这个 ...
 - sc7731 Android 5.1 LCD驱动简明笔记之一
			
基于展讯sc7731 - Android 5.1 代码分析浏览.将屏蔽细节,把握整体,并且不涉及其他设备和LCD的交互. 以下对sc7731 lcd大体流程进行简要说明. 第一,lcd 的两个阶段 1 ...
 - ICPC-CAMP day1 D.Around the world
			
Around the world 题目连接: 无 Description 给你一个n*n的矩阵,然后a[i][j]表示i,j是否有一条边 然后让你构造一个序列,使得i到(i+1)%n这两个点之间最多经 ...
 - DP总结 ——QPH
			
常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一 ...
 - 目标检測的图像特征提取之(一)HOG特征
			
1.HOG特征: 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检測的特征描写叙述子.它通过计算和统计图像局部区 ...
 - [AngularJS] Adding custom methods to angular.module
			
There are situations where you might want to add additional methods toangular.module. This is easy t ...
 - MySQL Handler变量解析
			
http://blog.itpub.net/29254281/viewspace-1159014/ To see the effect of a query do the following st ...
 - P、NP、NP-Complete、NP-hard问题
			
Table of Contents 1 遇到难题怎么办? 2 什么是P.NP.NP-Complete和NP-hard 3 P = NP ???? 4 参考 1 遇到难题怎么办? 遇到一个问题,通常我们 ...
 - [原创]Microsoft.AnalysisServices.ManagementDialogs.ServerPropertiesLanguagePanel 的类型初始值设定项引发异常
			
问题: 安装SQL SERVER 2012 SP1后,有可能在右键AS服务器想打开属性面板时候会出现如下错误: 解决: 这个需要安装相应的热修复补丁470544 相应文章: http://smal ...