yƒvƒƒOƒ‰ƒ€C:\MyJava\place\ApStart2.javaz**************************

import java.awt.*;
import javax.swing.*;
import java.util.*;


public class ApStart2 extends JApplet{
    //int[] place={1,2,3,4};                //4‰ÓŠ‚¾‚¯‚ÅŒvŽZ‚·‚éê‡
    //int[] place={1,2,3,4,5};
    //int[] place={1,2,3,4,5,6};
    //int[] place={1,2,3,4,5,6,7};
    int[] place={1,2,3,4,5,6,7,8};
    int min=10000;
    
    public void init(){
        int sum=0;
        DistanceTable d=new DistanceTable();
        d.put(1,2,45);
        d.put(3,1,245);
        d.put(2,3,145);
        d.put(1,4,95);
        d.put(3,4,225);
        d.put(2,4,14);
        d.put(1,5,15);
        d.put(2,5,91);
        d.put(3,5,22);
        d.put(4,5,54);
        d.put(1,6,34);
        d.put(2,6,45);
        d.put(3,6,191);
        d.put(4,6,122);
        d.put(5,6,74);
        d.put(1,7,154);
        d.put(2,7,4);
        d.put(3,7,245);
        d.put(4,7,1);
        d.put(5,7,132);
        d.put(6,7,84);
       
        d.put(1,8,54);
        d.put(2,8,55);
        d.put(3,8,25);
        d.put(4,8,41);
        d.put(5,8,12);
        d.put(6,8,184);
        d.put(7,8,71);
         
        AppletConsole ac=new AppletConsole(this);
        ArrayTest2 ar=new ArrayTest2();
        int[][] ar2=ar.makeArray(place);
        
        /*
         * ”z—ñ‚ð‘S•”•\Ž¦‚·‚é•”•ª
         */
        /*
        ac.append("\nŠJŽn\n");
        for(int i=0;i<ar2.length;i++){
            ac.append("\n");
            for(int j=0;j<ar2[i].length;j++){
                ac.append(ar2[i][j]+",");
            }
        }
        */
       
        int[] temp=new int[ar2.length];
        int[] bestway=new int[ar2.length]; 
        for(int i=0;i<ar2[0].length;i++){//**************** 3        
            ac.append("\n");
            for(int j=0;j<ar2.length;j++){
                temp[j]=ar2[j][i];
            }
            sum=d.distanceCalc(temp);
            ac.append("‹——£: "+sum);
            if(min>sum){
                min=sum;
                System.arraycopy(temp,0,bestway,0,temp.length);
            }
        }
        ac.append("\n");
        ac.append("Å’Z‹——£\n"+min+"\nÅ’Zƒ‹[ƒg\n");
        for(int i=0;i<bestway.length;i++){//**************** 3        
            ac.append(bestway[i]+",");
        }   
    }
}
        


class DistanceTable{
    HashMap<Integer,Integer> dtable;

    public DistanceTable(){
        dtable=new HashMap<Integer,Integer>();
    }
    
    void put(int p1,int p2,int distance){
        Key key=new Key(p1,p2);
        dtable.put(key.getKey(),distance);
    }
    
    int distanceCalc(int[] place){
        int sum=0;
        int key;
        for(int i=0;i<place.length-1;i++){
            key=new Key(place[i],place[i+1]).getKey();
           // System.out.println("Distance"+dtable.get(key));
            sum+=dtable.get(key);
        }
        return sum;
    }
}

class Key{
    private int key;
    
    Key(int p1,int p2){
        if(p2<p1)key=p2*10+p1;
        if(p1<p2)key=p1*10+p2;
        }
    
    int getKey(){
        return key;   
    }
}