• nyist -16



    #include <iostream>
    #include<cstring>
    using namespace std;
    struct node
    {
        int l,w;
    }dp[1005];
    int g[1005][1005];
    int d[1005];
    int n,max_v;
    int f(int i)
    {
        if (d[i]>0) return d[i];
        d[i]=1;
        for (int j=0;j<n;j++)
        {
            if (g[i][j])
                d[i]=max(d[i],f(j)+1);
        }
        max_v=max(max_v,d[i]);
        return d[i];
    }
    int main()
    {
      
        int N;
        cin>>N;
        while (N--)
        {
            cin>>n;
            int x,y;
             memset(g,0,sizeof(g));
            for (int i=0;i<n;i++)
            {
                cin>>x>>y;
                dp[i].l=max(x,y);
                dp[i].w=min(x,y);
            }
            for (int i=0;i<n;i++)
            {
                for (int j=i+1;j<n;j++)
                {
                    if (dp[i].l>dp[j].l && dp[i].w>dp[j].w)          g[j][i]=1;


                    else if ( dp[i].l<dp[j].l && dp[i].w<dp[j].w )      g[i][j]=1;

                    else g[j][i]=g[i][j]=0;
                }
                d[i]=0;
            }
            max_v=0;
            for (int i=0;i<n;i++)
                f(i);
            cout<<max_v<<endl;
        }
        return 0;
    }

    #include <iostream>

    using namespace std;


    struct node
    {
        int l,w;
    }dp[1005];


    int g[1005][1005];
    int d[1005];
    int k,max_v;
    int f(int i)
    {
        if (d[i]>0) return d[i];
        d[i]=1;
        for (int j=0;j<k;j++)
        {
            if (g[i][j])
                d[i]=max(d[i],f(j)+1);
        }
        max_v=max(max_v,d[i]);
        return d[i];
    }
    int main()
    {
        int n;
        cin>>n;
        while (n--)
        {
            cin>>k;
            int x,y;
            for (int i=0;i<k;i++)
            {
                cin>>x>>y;
                dp[i].l=max(x,y);
                dp[i].w=min(x,y);
            }


            for (int i=0;i<k;i++)
            {
                for (int j=i+1;  j<k;  j++)
                {
                    if (dp[i].l>dp[j].l && dp[i].w>dp[j].w)
                    {
                        g[j][i]=1;
                        g[i][j]=0;
                    }
                    else if (dp[i].l<dp[j].l && dp[i].w<dp[j].w)
                    {
                        g[j][i]=0;
                        g[i][j]=1;
                    }
                    else g[j][i]=g[i][j]=0;
                }
                d[i]=0;
            }
            max_v=0;
            for (int i=0;i<k;i++)
                f(i);
            cout<<max_v<<endl;
        }
        return 0;
    }
           

  • 相关阅读:
    数据挖掘十大经典算法
    280行代码:Javascript 写的2048游戏
    o​r​a​l​c​e​ ​D​B​A​ ​培​训_lesson06
    Word2007怎样从随意页開始设置页码 word07页码设置毕业论文
    iOS图片模糊效果
    linux(Ubuntu)安装QQ2013
    [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01
    【体系结构】转移预测器性能的定量评价
    Java实现 蓝桥杯VIP 算法提高 P0402
    Java实现 蓝桥杯VIP 算法提高 P0402
  • 原文地址:https://www.cnblogs.com/2014acm/p/3914393.html
Copyright © 2020-2023  润新知