Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define M 10
- /*
- * Aquí se usará recursión. Se supondrá que ya se a alcanzado el maximo puntaje en el movimiento anterior
- */
- int maxpuntaje(int tablero[M][M],int n,int m);
- int main(int argc, char** argv) {
- int n,m,i,j;
- int tablero[M][M];
- tablero[M][M]=0;
- //Recibimos los valores
- while(scanf("%d %d",&n,&m)!=EOF){
- for(i=0;i<n;i++){
- for(j=0;j<m;j++)
- scanf("%d",&tablero[i][j]);
- }
- printf("%d\n",maxpuntaje(tablero,n,m));
- }
- return (EXIT_SUCCESS);
- }
- int maxpuntaje(int tablero[M][M],int n,int m){
- int a,b;
- //caso base
- if((n==1)&&(m==1)){
- return tablero[0][0];
- }
- //cuando solo queda o una fila o una columna
- if (n==1){
- return tablero[n-1][m-1]+maxpuntaje(tablero,n,m-1);
- }
- if (m==1){
- return tablero[n-1][m-1]+maxpuntaje(tablero,n-1,m);
- }
- a=tablero[n-2][m-1];
- b=tablero[n-1][m-2];
- if (a>=b)
- return tablero[n-1][m-1]+maxpuntaje(tablero,n-1,m);
- else
- return tablero[n-1][m-1]+maxpuntaje(tablero,n,m-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment