c----------------------------------------------------------- c Chapter 3: Next k-subset of an n-set(p32) c----------------------------------------------------------- c Name of subroutine: NEXKSB c c Algorithm:Generating k-subset of {1,2,...,n} of an c n-set, in lexicographical order. c c----------------------------------------------------------- c----- The driver program is in nexksb_2.f ------------- c-----Subroutine begins here-------------------------------- subroutine nexksb(n,k,a,mtc) integer a(k),h logical mtc if(k.gt.0)goto 30 do 1 i=1,n 1 a(i)=0 mtc=.false. return 30 if(mtc) go to 40 20 m2=0 h=k go to 50 40 if(m2.lt.n-h) h=0 h=h+1 m2=a(k+1-h) 50 do 51 j=1,h 51 a(k+j-h)=m2+j mtc=a(1).ne.n-k+1 return end