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.

34 lines
535 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int n, m;
int cnt;
/**
测试数据:
5 1
答案:
3
*/
void dfs(int u, int s1, int s2) {
//收集答案
if (u == n + 1) {
if (s1 - s2 == m) cnt++;
return;
}
//选择了当前的数字
dfs(u + 1, s1 + a[u], s2);
//放弃了当前的数字
dfs(u + 1, s1, s2 + a[u]);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) a[i] = i;
dfs(1, 0, 0);
cout << cnt << endl;
return 0;
}