You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
752 B

2 years ago
#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;
}