HDU 1160
来源:互联网 发布:数据整理分析报告模板 编辑:程序博客网 时间:2024/06/06 07:39
题目大意:要证明老鼠越胖,跑的越慢。求最长的证明证据。每一行输入老鼠体重,速度,以文件结束跳出。
解题思路:将所有输入的老鼠,按输入顺序编号。然后按体重重优先与速度慢(体重轻优先与速度快)排序。然后用类似HDU1069长宽比较的方式,只是这里是,体重大于他之前,且速度慢与他之前,且只要算数量,但是要pre标记前一个编号为几。用于最后输出。
ac代码:
#include <iostream>#include <algorithm>using namespace std;struct node{int num;int weight;int speed;}mice[1005];int cnt=0, dp[1005], pre[1005], Max, temp, a[1005];bool compare(node a, node b){if (a.weight != b.weight)return a.weight < b.weight;if (a.speed != b.speed)return a.speed > b.speed;return a.num < b.num;}int main(){while (scanf("%d%d", &mice[cnt].weight, &mice[cnt].speed)!=EOF)mice[cnt].num = cnt + 1, dp[cnt++] = 1;sort(mice, mice+cnt, compare);for (int i=0; i<cnt; i++){pre[mice[i].num] = mice[i].num;for (int j=i-1; j>=0; j--)if (mice[j].weight < mice[i].weight && mice[j].speed > mice[i].speed){if (dp[i] < dp[j]+1)pre[mice[i].num] = mice[j].num;dp[i] = max(dp[i], dp[j]+1);}}Max = dp[0];temp = mice[0].num;for (int i=1; i<cnt; i++)if (Max < dp[i]){Max = dp[i];temp = mice[i].num;}printf("%d\n", Max);for (int i=0; i<Max; i++){a[i] = temp;temp = pre[temp];}for (int i=0; i<Max; i++)printf("%d\n", a[Max-i-1]);return 0;}
阅读全文
0 0
- hdu 1160
- hdu 1160
- HDU 1160
- HDU 1160
- hdu 1160
- HDU 1160
- HDU 1160
- HDU 1160
- hdu 1160
- hdu 1160
- HDU-1160
- HDU 1160
- hdu 1160
- HDU 1160
- HDU 1160 动态规划
- hdu 1160 排序
- hdu 1160 dp
- (1160)HDU-类LIS
- Ubuntu解决sudo: source: command not found错误
- 树状结构
- 文章标题
- no classfiles specifiedBUILD FAILED C:\Android\sdk\tools\ant\uibuild.xml:198: null returned: 1 解决方案
- Git和Github简单教程
- HDU 1160
- APP欢迎页跳转
- H5项目常见问题及注意事项
- 企业家应该选择DIY还是外包
- python里使用await关键字来等另外一个协程
- Struts2-通配符
- Linux的df命令详解
- mysql数据库错误码大全
- Android hashmap 顺序取值