多谢各位的回复,但经过考虑我想的问题是这样的,应当得出以下结果,14个字母的位置是不变动的
- b c d e f g h i j - - - -
- b c d e f g h i - k - - -
- b c d e f g h i - - l - -
- b c d e f g h i - - - m -
- b c d e f g h i - - - - n
a - c d e f g h i j - - - -
a - c d e f g h i - k - - -
a - c d e f g h i - - l - -
a - c d e f g h i - - - m -
a - c d e f g h i - - - - n
a b - d e f g h i j - - - -
a b - d e f g h i - k - - -
a b - d e f g h i - - l - -
a b - d e f g h i - - - m -
a b - d e f g h i - - - - n
a b c - e f g h i j - - - -
a b c - e f g h i - k - - -
a b c - e f g h i - - l - -
a b c - e f g h i - - - m -
a b c - e f g h i - - - - n
a b c d - f g h i j - - - -
a b c d - f g h i - k - - -
a b c d - f g h i - - l - -
a b c d - f g h i - - - m -
a b c d - f g h i - - - - n
a b c d e - g h i j - - - -
a b c d e - g h i - k - - -
a b c d e - g h i - - l - -
a b c d e - g h i - - - m -
a b c d e - g h i - - - - n
a b c d e f - h i j - - - -
a b c d e f - h i - k - - -
a b c d e f - h i - - l - -
a b c d e f - h i - - - m -
a b c d e f - h i - - - - n
a b c d e f g - i j - - - -
a b c d e f g - i - k - - -
a b c d e f g - i - - l - -
a b c d e f g - i - - - m -
a b c d e f g - i - - - - n
a b c d e f g h - j - - - -
a b c d e f g h - - k - - -
a b c d e f g h - - - l - -
a b c d e f g h - - - - m -
a b c d e f g h - - - - - n
rs1=split(temp,",")
dim rs2(13)
for i=0 to 13
rs2(i)=0
next
for i=cdbl(&h01234) to cdbl(&hdcba9) //循环从&h01234到&hdcba9,这个循环比较大,我本机测试用了2分钟,你可以考虑更改循环的值,分步得到结果
temp2=hex(i)
if len(temp2)=4 then temp2="0"+temp2
if(instr(temp2,"E")<=0 and instr(temp2,"F")<=0) then
b=""
for j=1 to 5
a=Mid(temp2, j, 1)
if instr(b,a)>0 then
for m=0 to 13
rs2(m)=0
next
exit for
else
b=b&a
rs2(eval("&h"+a))=1
if j=5 then
res=""
for m=0 to 13
if rs2(m)=0 then
res=res+rs1(m)
end if
rs2(m)=0
next
if(instr(res1,res)<=0) then
response.write res+"<br>"
res1=res1+res+","
end if
end if
end if
next
end if
next
<SCRIPT LANGUAGE=VBS>
'全排列的字典算法
dim n, i, j, k, temp
dim arr() '全局数组
n =6 : redim arr(n)
'数组赋初值
for i = 1 to n
arr(i) = i
next
document.write join(arr) & "<br>"
do
'从右到左找到第一个比右边数字小的数字位置
for j = n - 1 to 1 step -1
if arr(j) < arr(j + 1) then exit for
next
'结束则跳出循环
if j = 0 then exit do
'找出这个数右边比他大的最小数
for k = n to j + 1 step -1
if arr(k) > arr(j) then exit for
next
'交换之 (k, j)
temp = arr(j)
arr(j) = arr(k)
arr(k) = temp
'升序排列 j + 1 到 n
MySort j + 1, n
'打印一个结果
document.write join(arr) & "<br>"
loop
'升序排列, 冒泡法
function MySort(i, j)
dim k, m, temp
if i >= j then exit function
for m = j to i + 1 step -1
for k = i to m - 1
if arr(k) > arr(k + 1) then
temp = arr(k)
arr(k) = arr(k + 1)
arr(k + 1) = temp
end if
next
next
end function
</SCRIPT>
<INPUT id=t1 value=5><br>
<INPUT id=t2 value=5><br>
<INPUT id=t3 value=5><br>
<INPUT id=t4 value=1>
<p id=p></p>
<button onclick=vbs:SuperDullWolf id=button1 name=button1>笨狼24点牌DHTML递归算法</button>
<SCRIPT LANGUAGE=vbscript >
dim a(4),f(4),last
'计算4个数字的全排列
sub SuperDullWolf
dim count:count=0'计算无解的次数
p.innerHTML=""
for i1 =1 to 4
for i2 =1 to 4
for i3 =1 to 4
for i4 =1 to 4
if not(i1=i2 or i1=i3 or i1=i4 or i2=i3 or i2=i4 or i3=i4) then
a(1)=cint(eval("t" & i1 & ".value"))
a(2)=cint(eval("t" & i2 & ".value"))
a(3)=cint(eval("t" & i3 & ".value"))
a(4)=cint(eval("t" & i4 & ".value"))
if Iis24(a,4) then '如果找到答案就退出
exit sub
else
count=count+1'如果找不到答案继续尝试其他组合
end if
end if
Next
Next
Next
Next
if count>=24 then msgbox count & "无解!"
end sub
function sum(x,y,z)
on error resume next
sum=x
select case z
case 1
sum=sum+y
case 2
sum=sum-y
case 3
sum=sum*y
case 4
sum=sum/y
end select
last=x
end function
function showsum(x,y,z)
'显示
showsum=cstr(x)
select case z
case 1
showsum= showsum & "+" & y
case 2
showsum=showsum & "-" & y
case 3
showsum=showsum & "*" & y
case 4
showsum=showsum & "/" & y
end select
end function
function Iis24(ByRef a(),ByRef i)
if i=2 then
'如果剩下两个数直接判断
n1=a(1)
n2=a(2)'读入这两个数
for ff=1 to 4'遍历加减乘除
if sum(n1,n2,ff)=24 then
'输出结果
p.innerHTML=p.innerHTML & showsum(n1,n2,ff) & "=" & cstr(sum(n1,n2,ff)) & "<br>"
Iis24=true
exit function
else
if sum(n2,n1,ff)=24 then
'输出结果
p.innerHTML=p.innerHTML & showsum(n2,n1,ff) & "=" & cstr(sum(n2,n1,ff)) & "<br>"
Iis24=true
exit function
end if
end if
next
else
'如果有i个数,先去出两个来进行加减乘除
dim b(4),c(4)
for ii=1 to i
'取第一个数
n1=a(ii)
for jj=1 to i
if jj<>ii then
n2=a(jj)
'剩余放入数组C
nb=2
for kk=1 to i
if kk<>ii and kk<>jj then
c(nb)=a(kk)
nb=nb+1
end if
next
end if
next
for ff=1 to 4'便历加减乘除
c(1)=sum(n2,n1,ff) '取出两个数放到c中
if Iis24(c,i-1) then'递归
if sum(n2,n1,ff)=last then
p.innerHTML=p.innerHTML & showsum(n1,n2,ff) & "=" & sum(n1,n2,ff) & "<br>"
else
p.innerHTML=p.innerHTML & showsum(n2,n1,ff) & "=" & sum(n2,n1,ff) & "<br>"
end if
Iis24=true
exit function
end if
next
next
end if
end function
</SCRIPT>
<SCRIPT LANGUAGE=vbs>
'10多行代码实现n个数字全排列
dim n:n=4
dim S
dim w:w=0
for i=1 to n
S=S & "for i" & i & " =1 to n" & chr(13)
next
S=S & " if not("
for i=1 to n
for j=i to n
if i<>j then S=S & "i" & i & "=i" & j & " or "
next
next
S=left(S,len(S)-4) & ") then " & chr(13)
for i=1 to n
S=S & "document.write i" & i & chr(13)
next
S=S & "document.write " & chr(34) & "<br>" & chr(34) & chr(13) & "end if" & chr(13)
w=w+1
for i=1 to n
S=S & "Next" & chr(13)
next
execScript S,"vbs"
</SCRIPT>