zoukankan      html  css  js  c++  java
  • [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
    ", ans);
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    C# sqlhelp
    vs2015 C#打包程序为exe
    python3.6安装docx模块
    python 第八天
    python 第七天
    python 选课系统
    python 第六天
    python 模拟实现一个ATM + 购物商城程序
    python 计算器
    python 第五天
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/6905389.html
Copyright © 2011-2022 走看看