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 。。 185ms 新手编程请教大家

Posted by tintsing at 2009-07-17 19:49:17 on Problem 1088
#include<iostream>
using namespace std;
int main()
{
    int R,C,m,n,t1,t2;
    int i,j,k,p=0;
    int a[105][105],
        b[10005][2], 
        c[105][105];
    
    int ma[4][2]={{1,0},{-1,0},{0,-1},{0,1}};
    int MAX=0;
    while(cin>>R>>C){
    memset(c,0,sizeof(c));
    for(i=1;i<=R;i++)
     for(j=1;j<=C;j++)
      {
                      cin>>a[i][j];
                      b[++p][0]=a[i][j];
                      b[p][1]=p;
                      }
      
    for(i=1;i<p;i++)
     for(j=i+1;j<=p;j++)
      {
                        if(b[i][0]>b[j][0])
                        {
                                     t1=b[j][0];
                                     t2=b[j][1];
                                     b[j][0]=b[i][0];
                                     b[j][1]=b[i][1];
                                     b[i][0]=t1;
                                     b[i][1]=t2;
                                     
                                     }
                        }  

   for(i=1;i<=p;i++)
    {
                    int max=0;
                    if(b[i][1]%C!=0)
                    {
                                    m=b[i][1]/C+1;
                                    n=b[i][1]%C;}                    
                    else
                    {
                                    m=b[i][1]/C;
                                    n=C;}
                    for(j=0;j<4;j++)
                     if((c[m+ma[j][0]][n+ma[j][1]]>max)&&(a[m][n]>a[m+ma[j][0]][n+ma[j][1]]))
                      max=c[m+ma[j][0]][n+ma[j][1]];
                    
                    c[m][n]=++max;                     
                    if(c[m][n]>MAX)
                    MAX=c[m][n];
                    }
   cout<<MAX;
   MAX=0;
   }
    }

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