• 友好城市(LIS+结构体排序)


    友好城市

     解题思路:不交叉,则将北岸的坐标从小到大排,找南岸的最长上升子序列

    AC_Code

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <algorithm>
     5 #include <bits/stdc++.h>
     6 using namespace std;
     7 typedef long long ll;
     8 const int maxn = 5010;
     9 
    10 int dp[maxn];
    11 struct node{
    12     int north;
    13     int south;
    14 }a[maxn];
    15 
    16 bool cmp(node a, node b){
    17     return a.north<b.north;
    18 }
    19 
    20 int main()
    21 {
    22     int n,maxx=0;
    23     scanf("%d",&n);
    24     for(int i=0;i<n;i++){
    25         scanf("%d %d",&a[i].south, &a[i].north);
    26     }
    27     sort(a,a+n,cmp);
    28     for(int i=0;i<n;i++){
    29         for(int j=0;j<i;j++){
    30             if( a[i].south>a[j].south ){
    31                 dp[i] = max(dp[j]+1,dp[i]);
    32                 maxx = max(maxx,dp[i]);
    33             }
    34         }
    35     }
    36     printf("%d
    ",maxx+1);
    37     return 0;
    38 }
  • 相关阅读:
    站立会议报告(7)
    团队博客(13)
    团队博客(12)
    意见评论
    团队博客(11)
    团队博客(10)
    团队博客(9)
    团队博客(8)
    站立会议报告(6)
    Java Callable
  • 原文地址:https://www.cnblogs.com/wsy107316/p/12244299.html
Copyright © 2020-2023  润新知