比赛 |
NOIP水题争霸赛 |
评测结果 |
RRRRRRRRRR |
题目名称 |
博士的密码 |
最终得分 |
0 |
用户昵称 |
Matirx |
运行时间 |
0.001 s |
代码语言 |
C++ |
内存使用 |
0.19 MiB |
提交时间 |
2018-02-11 20:49:05 |
显示代码纯文本
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <iostream>
- #define ll long long
- using namespace std;
- int n,cnt;
- ll key,sum;
- ll a[45];
- void dfs(ll,int);
- int main()
- {
- //freopen("password1.in","r",stdin);
- //freopen("password1.out","w",stdout);
- scanf("%d%lld",&n,&key);
- for(int i = 1; i <= n; i++){
- scanf("%lld",&a[i]);
- }
- dfs(1,1);
- dfs(1,0);
- printf("%d",cnt);
- return 0;
- }
-
- void dfs(ll x,int y)
- {
- ll tmp = a[x] * y;
- ll m = sum + tmp;
- if(x > n) return;
- if(sum + tmp > key) return;
- for(int i = x; i <= n; i++) m += a[i];
- if(m < key) return;
- if(sum + tmp < key) {
- sum += tmp;
- dfs(x + 1,0);
- dfs(x + 1,1);
- sum -= tmp;
- }
- if(sum + tmp == key) {cnt++;return;}
- return;
- }