Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: Pablo
- *
- * Created on 22 de junio de 2014, 08:46 PM
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <limits.h>
- #define MAX_FIL 11
- #define MAX_COL 100
- void imprimirArreglo(int DP[MAX_FIL][MAX_COL], int fil, int col){
- int i,j;
- for (i=0;i<fil;i++){
- for(j=0;j<col;j++)
- printf("%4d",DP[i][j]);
- printf("\n");
- }
- }
- int minimo(int a, int b, int c){
- if (a<b){
- if (a<c)
- return a;
- else
- return c;
- }else{
- if(b<c)
- return b;
- else
- return c;
- }
- }
- void inicializarTabla(int DP[MAX_FIL][MAX_COL], int fil, int col){
- int i,j;
- for (i=0;i<fil;i++)
- for(j=0;j<col;j++)
- DP[i][j]=INT_MAX;
- }
- void llenarTabla(int DP[MAX_FIL][MAX_COL],int A[MAX_FIL][MAX_COL],
- int fil, int col){
- int a,i,j;
- for (a=0;a<fil;a++)
- DP[a][0]= A[a][0];
- for (j=1;j<col;j++)
- for(i=0;i<fil;i++){
- if (i==0){
- DP[i][j] = A[i][j] +
- minimo(DP[0][j-1],DP[fil-1][j-1],DP[1][j-1]);
- }
- else if(i==fil-1){
- DP[i][j] = A[i][j] +
- minimo(DP[fil-1][j-1],DP[fil-2][j-1],DP[0][j-1]);
- }
- else{
- DP[i][j] = A[i][j] +
- minimo(DP[i][j-1],DP[i+1][j-1],DP[i-1][j-1]);
- }
- }
- }
- int mejorCamino(int DP[MAX_FIL][MAX_COL],int fil,int col){
- int i,min;
- min = INT_MAX;
- for(i=0;i<fil;i++){
- if (DP[i][col-1]< min)
- min = DP[i][col-1];
- }
- return min;
- }
- void hallarFilas(int resultados[MAX_COL],int DP[MAX_FIL][MAX_COL],
- int fil, int col){
- int a,min,filAux,colAux;
- min = INT_MAX;
- for(a=0;a<fil;a++){
- if (DP[a][col-1]< min){
- min = DP[a][col-1];
- filAux = a;
- colAux = col-1;
- }
- }
- int i,j;
- for (i=colAux;i>=0;i--){
- }
- }
- int main(int argc, char** argv) {
- int fil,col,max;
- int A[MAX_FIL][MAX_COL];
- int DP[MAX_FIL][MAX_COL];
- int resultados[MAX_COL];
- while(scanf("%d %d",&fil,&col)!= EOF){
- int i,j,rpta;
- for (i=0;i<fil;i++)
- for(j=0;j<col;j++)
- scanf(" %d",&A[i][j]);
- inicializarTabla(DP,i,j);
- llenarTabla(DP,A,fil,col);
- /*printf("\n");
- imprimirArreglo(A,i,j);
- printf("\n");
- imprimirArreglo(DP,fil,col);*/
- rpta = mejorCamino(DP,fil,col);
- printf("%d",rpta);
- hallarFilas(resultados,DP,fil,col);
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement