hi Lego Haryanto
   i tried ur metoh but still not working ...here is my code and i m
tired with this program . i am not getting even a single method to find
lexicographic shortest path.


#include<stdio.h>

        int min1(int k,int m,int n)
                {
                                int min;
                                min=k;
                                if(min>m)
                                 min=m;
                                if(min>n)
                                  min=n;
                                return(min);
                }
        main()
        {

                int
m1[100][100],a[100][100],i,j,m,n,min,k,arr[100],t,min2,t1,t2,t3,v1;
                while(scanf("%d%d",&m,&n)==2)
                 {
                        for(i=0;i<m;i++)
                                for(j=0;j<n;j++)
                                        scanf("%d",&a[i][j]);

                        for(i=0;i<m;i++)
                                m1[i][0]=a[i][0];
                        for(j=1;j<n;j++)
                                for(i=0;i<m;i++)
                                        
m1[i][j]=a[i][j]+min1(m1[(i+m-1)%m][j-1],m1[i][j-1],m1[(i+1)%m][j-1]);

                        /*for(i=0;i<m;i++)
                                {
                                        for(j=0;j<n;j++)
                                                printf("%d    ",m1[i][j]);
                                                printf("\n");
                                }
                        printf("\n");*/
                        min2=m1[0][n-1];
                        k=0;
                        for(i=1;i<m;i++)
                                if(m1[i][n-1]<min2)
                                  {
                                        min2=m1[i][n-1];
                                        k=i;

                                  }
                        //printf("k=%d min=%d\n",k+1,min2);
                        arr[n-1]=k;
                        //printf("min=%d arr[%d]=%d\n",min2,n-1,arr[n-1]);
                        for(j=n-2;j>=0;j--)
                         {
                                //printf("j=%d ",j);
                                min=m1[(arr[j+1]+m-1)%m][j];
                                t1=(arr[j+1]+m-1)%m;
                                t=t1;
                                if(min>m1[arr[j+1]][j])
                                 {
                                        min=m1[arr[j+1]][j];
                                        t2=arr[j+1];
                                        t=t2;
                                 }
                                else if(min==m1[arr[j+1]][j])
                                 {
                                        t2=arr[j+1];
                                        if(t1>t2)
                                          t=t2;
                                        else
                                          t=t1;
                                 }

                                if(min>m1[(arr[j+1]+1)%m][j])
                                {
                                        min=m1[(arr[j+1]+1)%m][j];
                                        t3=(arr[j+1]+1)%m;
                                        t=t3;

                                }

                                else if(min==m1[(arr[j+1]+1)%m][j])
                                  {
                                        t3=(arr[j+1]+1)%m;
                                        if(t>t3)
                                          t=t3;
                                  }
                                arr[j]=t;
                                //printf("min=%d arr[%d]=%d\n",min,j,t);
                         }

                        for(i=0;i<=n-1;i++)
                                printf("%d ",arr[i]+1);
                                printf("\n%d\n",min2);
                }
        }


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to