这两段代码是属于深度优先搜索,还是属于分治??
代码一:
#include <stdio.h>
#include <string.h>
#define NUM 4
int set[NUM+1] = {0, 1, 2, 3, 4};
int subset[NUM+1] = {0};
void divide(int depth);
int main(void)
{
divide(1);
getchar();
return 0;
}
void divide(int depth)
{
char s[40] = {0};
int i;
if (depth == (NUM+1))
{
for (i = 1; i < depth; i++)
{
if (subset[i])
{
printf("%d ", set[i]);
}
}
printf("\n");
}
else
{
for (i = 0; i < 2; i++)
{
subset[depth] = i;
divide(depth+1);
}
}
}
代码二:
#include <stdio.h>
#include <string.h>
#define NUM 4
int set[NUM+1] = {0, 1, 2, 3, 4};
int subset[NUM+1] = {0};
void divide(int depth);
int main(void)
{
divide(1);
getchar();
return 0;
}
void divide(int depth)
{
char s[40] = {0};
int i;
if (depth == (NUM+1))
{
for (i = 1; i < depth; i++)
{
if (subset[i])
{
printf("%d ", set[i]);
}
}
printf("\n");
}
else
{
subset[depth] = 0;
divide(depth+1);
subset[depth] = 1;
divide(depth+1);
}
}