回溯法也稱為試探法
本實例是用回溯法輸出n個自然數中以r個數全排列
publicvoidArrange(intn
inti=
strings;
int[]a=newint[n];
a[i]=
while(true)
{
if((a[i]
{
if(i==(r
{
s=
for(j=
{
s=s+Convert
}
//Memo
Console
a[i]=a[i]+
continue;
}
i=i+
a[i]=a[i
}
else
{
if(i==
{
break;
}
i=i
a[i]=a[i]+
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12184.html