zoukankan      html  css  js  c++  java
  • P1434 [SHOI2002]滑雪

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int dx[4]={0,1,0,-1};
    const int dy[4]={1,0,-1,0};//四个方向
    int x,y;
    int tot=1,sum[10001]={0},ans=0;
    struct data
    {
        int x,y,h;
    }a[10001];//插歪坐标和高度
    bool cmp(data a,data b)
    {
        return a.h>b.h;
    }//比较高度
    bool check(int i,int j)
    {
        int k;
        for(k=0;k<=3;k++)//四方向试探
        {
            if(a[i].x+dx[k]==a[j].x && a[i].y+dy[k]==a[j].y)
            {
                return true;
            }
        }
        return false;
    }
    int main()
    {
        int i=0,j=0;
        cin>>x>>y;
        for(i=1;i<=x;i++)
        {
            for(j=1;j<=y;j++)
            {
                cin>>a[tot].h;
                a[tot].x=i;
                a[tot].y=j;
                tot++;
            }
        }
        sort(a+1,a+1+tot,cmp); 
        for(i=1;i<=tot;i++)
        {
          sum[i]=1;
            for (j=i-1;j>0;j--)
            {
              if (check(i,j)&&a[j].h>a[i].h)
               sum[i]=max(sum[i],sum[j]+1);//DP
            }
        }
        ans=0;
        for(i=1;i<=tot;i++)
        {
            ans=max(ans,sum[i]);
        }
        cout<<ans<<endl;
        return 0;
    }
    
  • 相关阅读:
    powershell,系统学习的第一种脚本语言
    mysql的source命令
    timer--计时器
    document.write 方法
    数组去重
    Abdicate
    轮播图
    使用 margin 让div块内容居中
    模运算 NOJ 1037
    模运算 NOJ 1037
  • 原文地址:https://www.cnblogs.com/LSWorld/p/9704035.html
Copyright © 2011-2022 走看看