题目
代码1
#include <bits/stdc++.h>
using namespace std;
set<string> s;
void dfs(int num1, int num2, int u, string ans)
{if (u == 7){if (num1 + num2 > 5)return;ans += (char)((num1) * 17 + num2);s.insert(ans);return;}for (int i = 0; i <= num1; i++){for (int j = 0; j <= num2; j++){if (i + j < 2 || i + j > 5 || num1 + num2 - i - j < 2)continue;char ch = i * 17 + j;dfs(num1 - i, num2 - j, u + 1, ans + ch);}}
}
int main()
{dfs(9, 16, 1, "");cout << s.size();
}
代码2
#include <bits/stdc++.h>
using namespace std;
int ans;
void dfs(int num1, int num2, int u)
{if (u > 7){if (num1 == 0 && num2 == 0)ans++;return;}for (int i = 0; i <= num1; i++){for (int j = 0; j <= num2; j++){if (i + j < 2 || i + j > 5)continue;dfs(num1 - i, num2 - j, u + 1);}}
}
int main()
{dfs(9, 16, 1);cout << ans;
}