[luoguP2782] 友好城市(DP)

传送门

 

转化成 lis 后 n2 搞就行

 

——代码

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 
 5 int n, max, ans;
 6 int f[10001];
 7 struct node
 8 {
 9     int a, b;
10 }q[10001];
11 
12 inline int read()
13 {
14     int x = 0, f = 1;
15     char ch = getchar();
16     for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
17     for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
18     return x * f;
19 }
20 
21 inline int Max(int x, int y)
22 {
23     return x > y ? x : y;
24 }
25 
26 inline bool cmp(node x, node y)
27 {
28     return x.a < y.a;
29 }
30 
31 int main()
32 {
33     int i, j, x, y;
34     n = read();
35     for(i = 1; i <= n; i++)
36     {
37         q[i].a = read();
38         q[i].b = read();
39     }
40     std::sort(q + 1, q + n + 1, cmp);
41     for(i = 1; i <= n; i++)
42     {
43         max = 0;
44         for(j = 1; j < i; j++)
45             if(q[j].b < q[i].b)
46                 max = Max(max, f[j]);
47         f[i] = max + 1;
48         ans = Max(ans, f[i]);
49     }
50     printf("%d\n", ans);
51     return 0;
52 }
View Code

 

转载于:https://www.cnblogs.com/zhenghaotian/p/6905389.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值