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.

35 lines
519 B

#include <iostream>
using namespace std;
const int N = 110;
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 + u, s2);
//放弃了当前的数字
dfs(u + 1, s1, s2 + u);
}
int main() {
cin >> n >> m;
dfs(1, 0, 0);
printf("%d\n", cnt);
return 0;
}