一个序列出现固定元素个数的方法(DFS)

#include <iostream.h>
int a[100];int i;
static int stat=0;
void dfs(int n,int oneCount)
{
    if(oneCount>2||n==3&&oneCount!=2)
        return ;
    if(n==3&&oneCount==2)
    { 
        for (i=0;i<n;i++)
        {
            cout<<a[i]<<'	';
        }
        cout<<endl;
        return ;
    }
   
    a[n]=0;dfs(n+1,oneCount);
    a[n]=1;dfs(n+1,oneCount+1);
 
}

void main()
{
    dfs(0,0); 
}
原文地址:https://www.cnblogs.com/ewitt/p/6607169.html