HDU 1160 FatMouse's Speed (DP)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_SIZE 1005 struct x
{
int weight;
int speed;
int num,sum,front;
}DP[MAX_SIZE]; int comp(const void * a,const void * b);
int main(void)
{
int i = ;
int max,max_loc,ans,ans_loc;
int box[MAX_SIZE]; while(scanf("%d%d",&DP[i].weight,&DP[i].speed) != EOF)
{
DP[i].num = i;
DP[i].sum = ;
DP[i].front = -;
i ++;
} qsort(DP,i,sizeof(struct x),comp); ans_loc = ;
ans = ;
for(int j = ;j < i;j ++)
{
max = ;
for(int k = ;k < j;k ++)
if(DP[j].weight > DP[k].weight && DP[j].speed < DP[k].speed)
if(DP[k].sum > max)
{
max = DP[k].sum;
max_loc = k;
} DP[j].sum += max;
if(max)
DP[j].front = max_loc; if(ans < DP[j].sum)
{
ans = DP[j].sum;
ans_loc = j;
}
} box[] = ans_loc;
i = ;
while(box[i] != -)
{
i ++;
box[i] = DP[box[i - ]].front;
} printf("%d\n",ans);
for(i --;i >= ;i --)
printf("%d\n",DP[box[i]].num + ); return ;
} int comp(const void * a,const void * b)
{
if((*(struct x *)a).weight == (*(struct x *)b).weight)
return (*(struct x *)b).speed - (*(struct x *)a).speed;
return (*(struct x *)a).weight - (*(struct x *)b).weight;
}
HDU 1160 FatMouse's Speed (DP)的更多相关文章
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU 1160 FatMouse's Speed (最长上升子序列)
题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- HDU 1160 FatMouse's Speed ——(DP)
又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...
随机推荐
- [转]log4net使用(WinForm/WebFrom)
原来的一篇文章,今天用 WLW 转到页面上,原文章以及附件下载地址:http://zhq.ahau.edu.cn/blog/article.asp?id=366 http://www.cnblogs. ...
- Xamarin.Android真机调试时闪退解决办法
项目->属性->Android Options,Packaging页签 去掉 Use Shared Runtime可解决
- Myeclipse 快捷键设置和自动提示设置
1.快捷键设置和调整 2.自动提示信息设置与调整
- 问题-Delphi2007跟踪变量时提示“E2171 Variable 'APolygon' inaccessible here due to optimization”
问题现象:Delphi2007跟踪变量时提示“E2171 Variable 'APolygon' inaccessible here due to optimization” . 问题原因:可能是因为 ...
- SaltStack安装(CentOS7.x)
安装基础: 参考文档:https://docs.saltstack.com/en/latest/topics/installation/rhel.html 1.导入SaltStack仓库key: wg ...
- 怎样提交FIREDAC数据集的DELTA到中间件然后保存进数据库
你可以在客户端序列FireDAC数据集的DELTA , 将序列后的STREAM发送给中间件, 中间件的TFDQuery或TFDMemTable调用LOADFROMSTREAM()方法加载流, 然后调用 ...
- VC中监测程序运行时间(二)-毫秒级
/* * 微秒级计时器,用来统计程序运行时间 * http://blog.csdn.net/hoya5121/article/details/3778487#comments * //整理 [10/1 ...
- GUI图形界面
一.界面元素 1.首层容器:Jwindow.JFrane(窗体).JDialge(对话框).JApplet. 2.组件:标签.文本框.密码框.按钮.下拉列表.单选框.复选框.文本域等 注:标签JLab ...
- URAL 2048 History 蔡勒公式
HistoryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- C#类索引器的使用
索引器提供了一种可以让类被当作数组进行访问的方式.在C#中,类索引器是通过this的属性实现的.index.ToString("D2")将index转换成一个具有两个字符宽度的字符 ...