Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

感觉 用结构体存行列和值 直接从小到大遍历DP就好了。

Posted by wdcjdtc at 2014-02-24 13:45:09 on Problem 1088
#include"cstdio"
#include"cmath"
#include"cstring"
#include"cstdlib"
#include"queue"
#include"iostream"
#include"algorithm"
#include"queue"
using namespace std;
struct hx
{
    int x,y,l;
}h[10005];
int move[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int n,m;
int cmp(const void *a,const void *b)
{
	return (*(struct hx*)a).l-(*(struct hx*)b).l;
}
int ok(int x,int y)
{
    if(x<0||y<0||x>=n||y>=m) return 0;
    return 1;
}
int dx(int x,int y)
{
    return x>y?x:y;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=-1)
    {
        int ans[105][105],v[105][105];
        int i,j;
        for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&v[i][j]);
        for(i=0;i<n;i++) for(j=0;j<m;j++) ans[i][j]=1;

        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                h[i*m+j].l=v[i][j];
                h[i*m+j].x=i;
                h[i*m+j].y=j;
            }
        }

        qsort(h,n*m,sizeof(h[0]),cmp);

        for(i=0;i<n*m;i++)
        {
            int xx,yy,k;
            for(k=0;k<4;k++)
            {
                xx=h[i].x+move[k][0];
                yy=h[i].y+move[k][1];
                if(ok(xx,yy))
                {
                    if(v[h[i].x][h[i].y]>=v[xx][yy]) continue;
                    ans[xx][yy]=dx(ans[xx][yy],ans[h[i].x][h[i].y]+1);
                }
            }
        }

        int max=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(ans[i][j]>max)
                    max=ans[i][j];
            }
        }
        printf("%d\n",max);
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator