C语言:
# include <stdio.h>
int num[ 1000 ] ;
int a;
void f ( int b, int c) {
if ( b == a) {
for ( int i = 0 ; i < a; i++ ) {
printf ( "%d " , num[ i] ) ;
}
printf ( "\n" ) ;
return ;
}
else {
for ( int i = 1 ; i <= 4 ; i++ ) {
if ( ! ( ( c >> i) & 1 ) ) {
num[ b++ ] = i;
f ( b, c | 1 << i) ;
b-- ;
}
}
}
}
int main ( ) {
a = 3 ;
f ( 0 , 0 ) ;
return 0 ;
}
shell脚本
bar=1
s_time=systime()
}
{
for(i=1;i<=NF;i++){
a[i]=$i
}
}
END{
# printf("%d\n",a[i])
n=5
m=3
k=1
combine(0,0,0)
#systime
e_time=systime()
g_time=e_time-s_time
printf("%d\n",g_time)
#b[i,j]
for(i=1;i<k;i++){
printf("%d:",i)
for(j=1;j<=m;j++){
printf("%s ",b[i,j])
}
printf("\n")
}
#input(x,y)
x=3
y=3
printf("(x,y)=%s\n",b[x,y])
}
function combine(u,sum,state){
if((sum+n-u) < m)
return;
if(sum == m) {
l=0
for(i=0;i<n;i++){
if(and(rshift(state,i),1)){
#printf("%d ",i+1)
b[k,++l]=a[i+1]
}
}
k++
#printf("\n")
return;
}
combine(u+1,sum+1,or(state,lshift(1,u)))
combine(u+1,sum,state)
}
在这里插入代码片