|
<>#include <stdio.h><BR>#include <conio.h><BR>#define N 6<BR>int a[N+1]={1,101,99,97,87,71,57};<BR>int b[N+1],results=0,mole;<BR>int chess[N+1][20]={0};<BR>void Comout(int m)<BR>{ int i,sum=0,j;<BR> int d[N+1]={0};<BR> if(m==1)<BR> {for(i=1;i<=N;i++)<BR> { for(j=1;j<=b;j++)<BR> if(chess[j]!=0)<BR> { sum+=j*a;<BR> d=j;<BR> }<BR> }<BR> if(sum==mole)<BR> { for(i=1;i<=N;i++)<BR> if(d!=0) printf("{%d,%d}",a,d);<BR> results++;<BR> printf("\n");<BR> }<BR> }<BR>}<BR>void Searchans(int acidnum,int line)<BR>{ int i,k,m=1,l=1;<BR> if(acidnum>0)<BR> {<BR> for(i=1;i<=b[line];i++)<BR> { chess[line]=1;<BR> /*k=acidnum-i*/<BR> if((k=acidnum-i)>=0)<BR> { do<BR> {Searchans(k,line+l);<BR> chess[line]=0;<BR> l++;<BR> }while (line+l==N);<BR> }<BR> else<BR> { chess[line]=0;<BR> Searchans(k,line+1);<BR> break;<BR> }<BR> }<BR> }<BR> else Comout(m);<BR>}</P>
<> void Find()<BR> { int i;<BR> /* mole-=18;*/<BR> for(i=1;i<=N;i++) b=mole/a;<BR> }</P>
<> void Finals()<BR> { printf("ans is :%d",results);}</P>
<P> void Getmole()<BR> { printf("please enter the mole:");<BR> scanf("%d",&mole);<BR> /*printf("mole is %d\n",mole);*/<BR> }<BR> void Making()<BR> { int i,j,k;<BR> for(j=0;j<=N;j++)<BR> for(i=b[j]+1;i<20;i++) chess[j]=-1;<BR> for(k=0;k<=N;k++)chess[k][0]=-1;<BR> }<BR>void main()<BR>{ int i,line,j;<BR> clrscr();<BR> Getmole();<BR> Find();<BR> /*Making();*/<BR> for(j=1;j<=N;j++) if(b[j]!=0) {line=j;break;}<BR> for(i=b[1];i<=b[N];i++) Searchans(i,line);<BR> Finals();<BR>}<BR></P> |
|