| 38 | System.out.println("*** ***** *****"); |
| 39 | } |
| 40 | static int tspdp(int c[][], int tour[], int start, int n) |
| 41 | { |
| 42 | int mintour[]=new int[10], temp[]=new int[10], mincost=999, ccost, i, j, k; |
| 43 | if(start == n-1) |
| 44 | { |
| 45 | return (c[tour[n-1]][tour[n]] + c[tour[n]][1]); |
| 46 | } |
| 47 | for(i=start+1; i<=n; i++) |
| 48 | { |
| 49 | for(j=1; j<=n; j++) |
| 50 | temp[j] = tour[j]; |
| 51 | temp[start+1] = tour[i]; |
| 52 | temp[i] = tour[start+1]; |
| 53 | if((c[tour[start]][tour[i]]+(ccost=tspdp(c,temp,start+1,n)))<mincost) |
| 54 | { |
| 55 | mincost = c[tour[start]][tour[i]] + ccost; |
| 56 | for(k=1; k<=n; k++) |
| 57 | mintour[k] = temp[k]; |
| 58 | } |
| 59 | } |
| 60 | for(i=1; i<=n; i++) |
| 61 | tour[i] = mintour[i]; |
| 62 | return mincost; |
| 63 | } |
| 64 | } |
| 65 | |