#include <iostream>
using namespace std;
void test(int x[])
{
if (10 == x[0] + x[1] + x[2] + x[3])
{
cout << x[0] << x[1] << x[2] << x[3] << endl;
}
}
void dfs(int x[], int cur)
{
if (4 == cur)
{
test(x);
return;
}
for (int i = 1; i < 4; i++)
{
x[cur] = i;
dfs(x, cur + 1);
}
}
int main()
{
int x[4] = {0};
dfs(x, 0);
return 0;
}
或者就是暴力 for循环
递归求 a+b+c+d == 10, a、b、c、d 都大于0小于5
最新推荐文章于 2020-03-19 22:52:12 发布