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.

38 lines
662 B

#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt;
vector<int> p1, p2;
/**
测试数据:
5 1
答案:
3
*/
void dfs(int u) {
//收集答案
if (u == n + 1) {
int s1 = 0, s2 = 0;
for (int i = 0; i < p1.size(); i++)
s1 += p1[i];
for (int i = 0; i < p2.size(); i++)
s2 += p2[i];
if (s1 - s2 == m)
cnt++;
return;
}
p1.push_back(u);
dfs(u + 1);
p1.pop_back();
p2.push_back(u);
dfs(u + 1);
p2.pop_back();
}
int main() {
cin >> n >> m;
dfs(1);
cout << cnt << endl;
return 0;
}