HDU
来源:互联网 发布:nginx 禁止某ip访问 编辑:程序博客网 时间:2024/05/22 03:11
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160
题意:给你一堆重量和速度,要你求重量越来越重,速度越来越慢的最多个数并输出
思路:就是一个两个条件的LIS和打印路径,先按重量排一下序,然后LIS,用p数组记录前驱,然后打印就行了
代码:
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1using namespace std;typedef long long LL;typedef pair<LL, LL> P;const int maxn = 1e3 + 5;const int mod = 1e8 + 7;struct node { int w; int s; int key;} a[maxn];bool cmp(node a, node b) { if (a.w < b.w) return 1; else if (a.w == b.w && a.s > b.s) return 1; else return 0;}int p[maxn], dp[maxn], ans[maxn];int main() { int num = 0; memset(p, -1, sizeof(p)); memset(dp, 0, sizeof(dp)); while (~scanf ("%d%d", &a[num].w, &a[num].s)) { a[num].key = num + 1; p[num] = 0; dp[num] = 1; num++; } sort(a, a + num, cmp); int Max = -INF, Maxi; for (int i = 0; i < num; i++) { for (int j = 0; j < i; j++) { if (a[i].w > a[j].w && a[i].s < a[j].s && dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; p[i] = j; if (dp[i] > Max) { Max = dp[i]; Maxi = i; } } } } printf ("%d\n", Max); int cnt = 0; while (Maxi) { ans[cnt++] = Maxi; Maxi = p[Maxi]; } while (Max--) { printf ("%d\n", a[ans[Max]].key); } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- Android购物车demo(多店铺带商品,类似京东购物车)
- 1033. To Fill or Not to Fill (25) 贪心算法
- 一个菜鸟的前端之路----遇到的坑
- Java8学习笔记
- java程序员的大数据之路(12):Hadoop的守护进程
- HDU
- Python资源汇总
- 171123 逆向-TLS回调函数
- Java装饰设计模式
- python编码
- 网格从左下角移动到右上角有多少种路线(动态规划)
- lucene源代码学习之FST(Finite State Transducer)在SynonymFilter中的实现思想
- MFC学习笔记8 对话框与程序连接
- Mysql批量操作2(批量删除)