'commit'
This commit is contained in:
38
TangDou/KaoShi/小蓝突发奇想2.cpp
Normal file
38
TangDou/KaoShi/小蓝突发奇想2.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user