Advertisement
Gustavo_Inzunza

incompleto asenjo

Jul 17th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstdio>
  3. using namespace std;
  4. int ma[100][100],mayor,filas,columnas;
  5. int rec[100][100];
  6. int mejor(int i,int j, int suma){
  7.     if(j==-1||j==columnas) return 0;
  8.     //if(rec[i][j]>=3) return 0;
  9.     if(i==filas-1){
  10.         return suma+ma[i][j];
  11.         }
  12.     ++rec[i][j];
  13.     mayor=max(mayor,mejor(i+1,j-1,suma+ma[i][j]));
  14.    
  15.     mayor=max(mayor,mejor(i+1,j,suma+ma[i][j]));
  16.    
  17.     mayor=max(mayor,mejor(i+1,j+1,suma+ma[i][j]));
  18.     return mayor;
  19.    
  20. }
  21. bool valida(int i,int j){
  22.     if(i<0||i>=filas) return false;
  23.     if(j<0||j>=columnas) return false;
  24.     return true;
  25.    
  26.     }
  27. int main(){
  28.     int T,m,n;
  29.     scanf("%d",&T);
  30.     for(int test=0;test<T;test++){
  31.         scanf("%d %d",&filas,&columnas);
  32.         for(int i=0;i<filas;i++)
  33.             for(int j=0;j<columnas;j++){
  34.             scanf("%d",&ma[i][j]);
  35.         rec[i][j]=0;
  36.         }
  37.             mayor=0;
  38.             int suma[100];
  39.             for(int i=0;i<columnas;i++)
  40.             suma[i]=ma[0][i];
  41.             int cf=1;
  42.             while(cf<filas){
  43.                
  44.                 for(int j=0;j<columnas;j++){
  45.                     int mayora=ma[cf][j];
  46.                     //mayor de 3
  47.                    
  48.                     if(valido(cd,j-1))
  49.                     mayora=max(mayora,max());
  50.                     if(valido(cf,j+1))
  51.                     suma[j]=suma[j]+mayora;
  52.                     mayor=max(suma[j],mayor);
  53.                     }
  54.                 //avanza f
  55.                 ++cf;
  56.                 }
  57.             //for(int j=0;j<columnas;j++)
  58.         //mayor=max(mayor,mejor(0,j,0));
  59.         printf("%d\n",mayor);
  60.         }
  61.    
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement