Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : unlucky_13
- Problem_link :
- Category :
- Algorithm_Used :
- */
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #define LL long long int
- //const long long int inf = 2147483647 ;
- //const int minx=;
- //const int maxn=;
- using namespace std;
- int x_move[]={-1,0,1,0} ;
- int y_move[]={0,-1,0,1} ;
- int M[111][111],r,c ;
- int dp[111][111] ;
- bool check(int a,int b){
- if(a<0 || a>r || b<0 ||b>c) return 0 ;
- return 1 ;
- }
- int f(int u,int v,int val){
- //cout<<u<<" "<<v<<endl ;
- if(dp[u][v]!=-1) return dp[u][v] ;
- int ret = 0 ;
- for(int i=0;i<4;i++){
- int X = u+x_move[i] ;
- int Y = v+y_move[i] ;
- if(check(X,Y) && M[X][Y]>val)
- {
- ret = max(ret,f(X,Y,M[X][Y])) ;
- }
- }
- dp[u][v]=ret+1 ;
- return dp[u][v] ;
- }
- int main() {
- //freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
- int tc ;
- char name[111] ;
- scanf("%d\n",&tc) ;
- while(tc--){
- scanf("%s %d %d",name,&r,&c) ;
- memset(dp,-1,sizeof(dp)) ;
- for(int i=0;i<r;i++){
- for(int j=0;j<c;j++) scanf("%d",&M[i][j]) ;
- }
- int ans = 0 ;
- for(int i=0;i<r;i++){
- for(int j=0;j<c;j++) ans = max(ans,f(i,j,M[i][j])) ;
- }
- printf("%s: %d\n",name,ans) ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment