//填写备忘录表。查询。 //从低到高递归填写备忘录。 //最初数据,经过几次抉择,产生更多数据。 public static class dynamicProcess { public static void test() { int[] specification={ 0,1,5,8,9,10,17,17,20,24,30}; //fill noteTable. Integer[] NoteTable=new Integer[6]; NoteTable[0]=0; fillTable(NoteTable, specification); int length=5; LSLog.printLine(length+" best:"+NoteTable[length], 1); } private static void fillTable(Integer[] table,int[] specifition) { //get each question's best value from 1 to target. for(int i=1;i<=table.length-1;i++) { //get all group. compare each group's value,and get bestValue. MyLinkedList> ret=resultList(i,i-1); int bestValue=bestValue(ret,specifition,i,table); LSLog.printLine("---------------------------", 1); table[i]=bestValue; } } //size:原始数据 .level:进行第几个抉择。 //对一个多抉择点问题,进行递归抉择。分解:n-1 的结果删除最后一个,再插入2中可能。最小解:level=0,无抉择,创建初值。 private static MyLinkedList > resultList(Integer size,Integer level) { assert(size!=null&& size>0):"data is illvalible."; if(level==0) { MyLinkedList temp=new MyLinkedList (); temp.add(size); MyLinkedList > bbLinkedList=new MyLinkedList >(); bbLinkedList.add(temp); return bbLinkedList; } else { MyLinkedList > tempret=resultList(size, level-1); MyLinkedList > tempnew=new MyLinkedList >(); for(int i=0;i theOneCopy=tempret.get(i).clone(); MyLinkedNode theNode=theOneCopy.getNode(theOneCopy.size()-1); Integer theValueInteger=theNode.mdata; int cutValue= level-(size-theOneCopy.mLast.mPre.mdata); theOneCopy.remove(theOneCopy.getNode(theOneCopy.size()-1)); theOneCopy.add(cutValue); theOneCopy.add(theValueInteger-cutValue); tempnew.add(theOneCopy); } for(int i=0;i > ret,int[] specifition,int level,Integer[] table) { int bestValue=-1; for(int i=0;i theAnswer=ret.get(i); for(int h=0;h tempValue?bestValue:tempValue; LSLog.printLine("******"+tempValue +".best."+bestValue, 1); } return bestValue; } }