資源簡介
這是一個用Java實現圖的m著色問題的算法
代碼片段和文件信息
import?javax.swing.JOptionPane;
public?class?Coloring?{
????static?int?n?????????????//圖的頂點數
???????????????m;?????????????//可用顏色數
????static?boolean[][]?a?=?{??//圖的鄰接矩陣
???? {falsefalsefalsefalsefalsefalse}
???? {falsefalsetruetruetruefalse}
???? {falsetruefalsetruetruetrue}
???? {falsetruetruefalsetruefalse}
???? {falsetruetruetruefalsetrue}
???? {falsefalsetruefalsetruefalse}
????};
????static?int[]?x;???????????//當前解
????static?long?sum;??????????//當前已找到的可m著色方案數
????
????public?static?void?main(String[]?args)?throws?Exception?{
???? n?=?a[0].length-1;
???? try?{
???? m?=?Integer.parseInt(JOptionPane.showInputDialog(null?“請輸入可用的顏色數,例如:3“?“輸入“?
???? JOptionPane.INFORMATION_MESSAGE));
???? }?catch(NumberFormatException?e1)?{
???? JOptionPane.showMessageDialog(null?“數據格式不正確,請重新運行程序輸入!“?“提示“?
???? JOptionPane.WARNING_MES
評論
共有 條評論