Advertisement
Farjana_akter

Untitled

Jun 5th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4.  
  5.  
  6.  
  7. int row,col,run,arr[105][105];
  8.  
  9.  
  10. void longestrun(int i,int j,int x,int pre)
  11. {
  12. if(arr[i][j]>=pre || i==0 || j==0 || i>row || j>col )
  13. {
  14. run=max(run,x);
  15. return;
  16. }
  17. longestrun(i,j+1,x+1,arr[i][j]);
  18. longestrun(i,j-1,x+1,arr[i][j]);
  19. longestrun(i+1,j,x+1,arr[i][j]);
  20. longestrun(i-1,j,x+1,arr[i][j]);
  21. }
  22.  
  23. int main()
  24. {
  25. string s;
  26. int t,cas,i,j,k,n,m;
  27. cin>>t;
  28. while(t--)
  29. {
  30. cin>>s>>row>>col;
  31. cout<<s<<": ";
  32. for(i=1; i<=row; i++)
  33. {
  34. for(j=1; j<=col; j++)
  35. {
  36. cin>>arr[i][j];
  37. }
  38. }
  39. run=0;
  40. for(i=1; i<=row; i++)
  41. {
  42. for(j=1; j<=col; j++)
  43. {
  44. longestrun(i,j+1,1,arr[i][j]);
  45. longestrun(i,j-1,1,arr[i][j]);
  46. longestrun(i+1,j,1,arr[i][j]);
  47. longestrun(i-1,j,1,arr[i][j]);
  48. }
  49. }
  50. cout<<run<<endl;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement