unlucky_13

uva_10285

May 31st, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. /*
  2.  Author                             :     unlucky_13
  3.  Problem_link                       :
  4.  Category                           :
  5.  Algorithm_Used                     :
  6.  */
  7.  
  8. #include<cstdio>
  9. #include<sstream>
  10. #include<cstdlib>
  11. #include<cctype>
  12. #include<cmath>
  13. #include<algorithm>
  14. #include<set>
  15. #include<queue>
  16. #include<stack>
  17. #include<list>
  18. #include<iostream>
  19. #include<fstream>
  20. #include<numeric>
  21. #include<string>
  22. #include<vector>
  23. #include<cstring>
  24. #include<map>
  25. #include<iterator>
  26. #define LL long long int
  27. //const long long int inf = 2147483647 ;
  28. //const int minx=;
  29. //const int maxn=;
  30. using namespace std;
  31. int x_move[]={-1,0,1,0} ;
  32. int y_move[]={0,-1,0,1} ;
  33. int M[111][111],r,c ;
  34. int dp[111][111] ;
  35. bool check(int a,int b){
  36.     if(a<0 || a>r || b<0 ||b>c) return 0 ;
  37.     return 1 ;
  38. }
  39.  
  40. int f(int u,int v,int val){
  41.  
  42.     //cout<<u<<" "<<v<<endl ;
  43.     if(dp[u][v]!=-1) return dp[u][v] ;
  44.     int ret = 0 ;
  45.     for(int i=0;i<4;i++){
  46.         int X = u+x_move[i] ;
  47.         int Y = v+y_move[i] ;
  48.         if(check(X,Y) && M[X][Y]>val)
  49.         {
  50.             ret = max(ret,f(X,Y,M[X][Y])) ;
  51.  
  52.         }
  53.     }
  54.  
  55.     dp[u][v]=ret+1 ;
  56.     return dp[u][v] ;
  57.  
  58.  
  59. }
  60.  
  61. int main() {
  62.  
  63.  
  64.     //freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
  65.     int tc ;
  66.     char name[111] ;
  67.     scanf("%d\n",&tc) ;
  68.     while(tc--){
  69.         scanf("%s %d %d",name,&r,&c) ;
  70.         memset(dp,-1,sizeof(dp)) ;
  71.         for(int i=0;i<r;i++){
  72.             for(int j=0;j<c;j++) scanf("%d",&M[i][j]) ;
  73.         }
  74.  
  75.         int ans = 0 ;
  76.         for(int i=0;i<r;i++){
  77.             for(int j=0;j<c;j++) ans = max(ans,f(i,j,M[i][j])) ;
  78.         }
  79.         printf("%s: %d\n",name,ans) ;
  80.  
  81.     }
  82.  
  83.  
  84.  
  85.     return 0;
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment