WOMEN 1065年&1025年の推定

私は愚かな...私はこの問題にワイド非常に多くの時間を持っていますよ...

このアプリケーションは、理論の非常に素晴らしい、魔法のディルワースの定理である、あなたは自分自身でそれをグーグルことができます

木材特性(昇順に例えば長さ)で、次いで最長は(本明細書の他の特性に向けられている立下り)変換シーケンスのアイデアをドロップするように、DPを解決しました。

タイトルに相当実際には、条件は、セットアップ時間が半順序として見られている必要はありません、これは明らかにディルワース定理です。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn= 5e3+5;
const int INF= 0x7f7f7f7f;
struct Wod{
    int l, w;
    Wod()= default;
    Wod(int ll, int ww) : l(ll), w(ww) {}
    bool operator < (const Wod& a) const{
        return l< a.l || (l== a.l && w< a.w);
    }
}wds[maxn];
int lds[maxn], flg[maxn];
int ans= -INF;

void Init()
{
    memset(flg, 0, sizeof(flg));
    memset(lds, 0, sizeof(lds));
    memset(wds, 0, sizeof(wds));
}
int main()
{
    int T, n;
    scanf("%d", &T);

    while (T--){
        Init();
        scanf("%d", &n);

        int l, w;
        for (int i= 1; i<= n; ++i){
            scanf("%d %d", &l, &w);
            wds[i]= Wod(l, w);
        }
        sort(wds+1, wds+n+1);

        for (int i= 1; i<= n; ++i){
            for (int j= 1; j< i; ++j){
                if (wds[j].w > wds[i].w && lds[j] > lds[i]){
                    lds[i]= lds[j];
                }
            }
            ++lds[i];
            ans= max(ans, lds[i]);
        }
        printf("%d\n", ans);
    }

    return 0;
}

おすすめ

転載: www.cnblogs.com/Idi0t-N3/p/12499522.html