This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
/*
输入:8
答案:3
*/
int n;
int res;
// r:待分拆的数字
// last:记录上一个分拆的数字是什么
void dfs(int u, int r, int last) {
if (u == 4) {
if (r == 0) res++; //如果完成分拆的数字恰好等于n,说明是成功的分拆,否则就是没用完有剩余
return;
}
for (int i = last + 1; i <= r; i++) //必须大于上一个,才能保证唯一不重复
if (i != 3 && i != 7) dfs(u + 1, r - i, i); //当前位置不能分配3和7
int main() {
cin >> n;
dfs(1, n, 0); //站在第1个箱子面前,待分拆的数是n,上一个分拆完的数字是0,
printf("%d\n", res);
return 0;