| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | 
							- import math
 
- #获取阶乘列表
 
- def jieChen(n):
 
-     myArray = {};
 
-     myArray[0] = 1;
 
-     i = 1;
 
-     while i<n :
 
-         myArray[i] = (i+1)*myArray[i-1];
 
-         i = i+1
 
-     return myArray;
 
- #获取阶乘排列数组
 
- def jiechenarray(n):
 
-     array = [];
 
-     if n < 1:
 
-         return array
 
-     if n == 1:
 
-         onearray = [];
 
-         onearray.append(n)
 
-         array.append(onearray)
 
-         return array
 
-     subArray = jiechenarray(n-1);
 
-     subArrayLength = len(subArray)
 
-     for item in range(subArrayLength):
 
-         for index in range(len(subArray)+1):
 
-             newArrayItem = subArray[item].copy()
 
-             newArrayItem.insert(index,n)
 
-             array.append(newArrayItem)
 
-     return array
 
- #获取指定数的阶乘
 
- def jieChenNumber(n):
 
-     if(n <= 1):
 
-         return 1;
 
-     return jieChen(n)[n-1];
 
- #辗转相除法进行进制转化
 
- def changeInt2Str(i,m):
 
-     if(not isinstance(m,int)):
 
-         print("m is not int",m)
 
-         return
 
-     if(m*i == 0):
 
-         return "0";
 
-     result = "";i
 
-     myarray = {};
 
-     while(i>=m):
 
-         myarray[myarray.__len__()] = i%m
 
-         i=int(i/m)
 
-     if(i!=0):
 
-         myarray[myarray.__len__()] = i
 
-     for item in myarray :
 
-         result=str(myarray[item])+result
 
-     return result
 
- #获取组合数位置列表
 
- def getAllPosition(m, n):
 
-     allArray = {}
 
-     max = math.pow(m,n)
 
-     index = 0;
 
-     while (index < max):
 
-         itemIndex = changeInt2Str(index,m)
 
-         while(itemIndex.__len__()<n):
 
-             itemIndex = "0"+itemIndex
 
-         allArray[index]=itemIndex
 
-         index = index+1
 
-     print(allArray)
 
-     return allArray
 
- #获取组合数列表的排列总数
 
- def getAllArrayNumber(m,n):
 
-     total = 0
 
-     allArray = getAllPosition(m, n)
 
-     for item in allArray:
 
-         total = getitemIndexArrayNumber(allArray[item],m,n)+total
 
-         print("total=",total)
 
-     return total
 
- #获取单个组合的各边重复项
 
- def getitemIndexArray(itemIndex,m,n):
 
-     a = {};
 
-     for item in range(m):
 
-         index = 0;
 
-         indexNum = 0;
 
-         while(index < n):
 
-             if(itemIndex[index] == str(item)):
 
-                 indexNum = indexNum + 1
 
-             index = index+1
 
-         a[item]=indexNum
 
-     print("a=",a)
 
-     return a
 
- #获取单个组合的各边重复项--包含各项位置
 
- # 如{0: {0: 0, 1: {}}, 1: {0: 0, 1: {}}, 2: {0: 2, 1: {0: 0, 1: 4}}, 3: {0: 3, 1: {0: 1, 1: 2, 2: 3}}, 4: {0: 0, 1: {}}}
 
- def getitemIndexAndPositionArray(itemIndex, m, n):
 
-     a = {};
 
-     for item in range(m):
 
-         index = 0;
 
-         indexNum = 0;
 
-         positions = {};
 
-         while(index < n):
 
-             if(itemIndex[index] == str(item)):
 
-                 positions[len(positions)] = index
 
-                 indexNum = indexNum + 1
 
-             index = index+1
 
-         aItem = {}
 
-         aItem[0] = indexNum
 
-         aItem[1]=positions
 
-         a[item]=aItem
 
-     print("a=",a)
 
-     return a
 
- #获取单个组合的各边重复项的排列数
 
- def getitemIndexArrayNumber(itemIndex,m,n):
 
-     itemIndexArrayNumber = 0;
 
-     a = getitemIndexArray(itemIndex,m,n)
 
-     for item in a:
 
-         intItem = int(a[item])
 
-         if(intItem > 1):
 
-             itemIndexArrayNumber = jieChenNumber(intItem)+itemIndexArrayNumber
 
-     if(itemIndexArrayNumber == 0):
 
-         itemIndexArrayNumber = 1
 
-     return itemIndexArrayNumber
 
- # result = changeInt2Str(14,3);
 
- # print(result)
 
- # getAllPosition(3, 3)
 
- # getAllArrayNumber(4,3)
 
- # getitemIndexArray("01243",5,5)
 
- # getitemIndexAndPositionArray("23332", 5, 5)
 
- # number = getitemIndexArrayNumber("51243",5)
 
- # print(number)
 
- # getAllArrayNumber(4,2)
 
- # print(jiechenarray(3))
 
 
  |