'commit'
This commit is contained in:
35
TangDou/LanQiaoBei/LanQiao12ShengSai/BC5.cpp
Normal file
35
TangDou/LanQiaoBei/LanQiao12ShengSai/BC5.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user