zoukankan      html  css  js  c++  java
  • [NYIST16]矩形嵌套(DP,最长上升子序列)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=16

    像套娃一样把矩形套起来。先给矩形从小到大排序,然后做最长上升子序列就行

      1 /*
      2 ━━━━━┒ギリギリ♂ eye!
      3 ┓┏┓┏┓┃キリキリ♂ mind!
      4 ┛┗┛┗┛┃\○/
      5 ┓┏┓┏┓┃ /
      6 ┛┗┛┗┛┃ノ)
      7 ┓┏┓┏┓┃
      8 ┛┗┛┗┛┃
      9 ┓┏┓┏┓┃
     10 ┛┗┛┗┛┃
     11 ┓┏┓┏┓┃
     12 ┛┗┛┗┛┃
     13 ┓┏┓┏┓┃
     14 ┃┃┃┃┃┃
     15 ┻┻┻┻┻┻
     16 */
     17 #include <algorithm>
     18 #include <iostream>
     19 #include <iomanip>
     20 #include <cstring>
     21 #include <climits>
     22 #include <complex>
     23 #include <fstream>
     24 #include <cassert>
     25 #include <cstdio>
     26 #include <bitset>
     27 #include <vector>
     28 #include <deque>
     29 #include <queue>
     30 #include <stack>
     31 #include <ctime>
     32 #include <set>
     33 #include <map>
     34 #include <cmath>
     35 using namespace std;
     36 #define fr first
     37 #define sc second
     38 #define cl clear
     39 #define BUG puts("here!!!")
     40 #define W(a) while(a--)
     41 #define pb(a) push_back(a)
     42 #define Rint(a) scanf("%d", &a)
     43 #define Rll(a) scanf("%I64d", &a)
     44 #define Rs(a) scanf("%s", a)
     45 #define Cin(a) cin >> a
     46 #define FRead() freopen("in", "r", stdin)
     47 #define FWrite() freopen("out", "w", stdout)
     48 #define Rep(i, len) for(LL i = 0; i < (len); i++)
     49 #define For(i, a, len) for(LL i = (a); i < (len); i++)
     50 #define Cls(a) memset((a), 0, sizeof(a))
     51 #define Clr(a, x) memset((a), (x), sizeof(a))
     52 #define Fuint(a) memset((a), 0x7f7f, sizeof(a))
     53 #define lrt rt << 1
     54 #define rrt rt << 1 | 1
     55 #define pi 3.14159265359
     56 #define RT return
     57 #define lowbit(x) x & (-x)
     58 #define onenum(x) __builtin_popcount(x)
     59 typedef long long LL;
     60 typedef long double LD;
     61 typedef unsigned long long Uint;
     62 typedef pair<LL, LL> pii;
     63 typedef pair<string, LL> psi;
     64 typedef map<string, LL> msi;
     65 typedef vector<LL> vi;
     66 typedef vector<LL> vl;
     67 typedef vector<vl> vvl;
     68 typedef vector<bool> vb;
     69 
     70 typedef struct Square {
     71     int x, y;
     72     Square() {}
     73     Square(int xx, int yy) : x(xx), y(yy) {}
     74 }Square;
     75 
     76 const int maxn = 1010;
     77 Square s[maxn];
     78 int n;
     79 int dp[maxn];
     80 
     81 bool cmp(Square a, Square b) {
     82     if(a.x == b.x) return a.y <= b.y;
     83     return a.x < b.x;
     84 }
     85 
     86 bool ok(Square a, Square b) {
     87     return a.x > b.x && a.y > b.y;
     88 }
     89 
     90 int main() {
     91     // FRead();
     92     int T, x, y;
     93     Rint(T);
     94     W(T) {
     95         Cls(dp);
     96         Rint(n);
     97         For(i, 1, n+1) {
     98             Rint(x); Rint(y);
     99             if(x > y) swap(x, y);
    100             s[i] = Square(x, y);
    101         }
    102         sort(s+1, s+n+1, cmp);
    103         int ret = 0;
    104         For(i, 2, n+1) {
    105             dp[i] = 0;
    106             For(j, 1, i+1) {
    107                 if(ok(s[i], s[j])) {
    108                     dp[i] = max(dp[i], dp[j]+1);
    109                 }
    110             }
    111             ret = max(dp[i], ret);
    112         }
    113         printf("%d
    ", ret+1);
    114     }
    115     RT 0;
    116 }
  • 相关阅读:
    idea中编译项目报错 java: javacTask: 源版本 1.8 需要目标版本 1.8
    发布返回结果对象中添加冒泡结果字段
    Spring还使用基于 JSR-250 注释,它包括 @PostConstruct, @PreDestroy 和 @Resource 注释
    跨网段IP
    Vlan
    分区工具parted的详解及常用分区使用方法
    dump命令详解
    备份 (综述)
    firewalld 防火墙配置
    find、which、whereis、locate和type之间的区别
  • 原文地址:https://www.cnblogs.com/kirai/p/5570804.html
Copyright © 2011-2022 走看看