比赛 |
NOIP水题争霸赛 |
评测结果 |
WWWWWWWWWW |
题目名称 |
博士的密码 |
最终得分 |
0 |
用户昵称 |
Joker |
运行时间 |
0.013 s |
代码语言 |
C++ |
内存使用 |
1.12 MiB |
提交时间 |
2018-02-11 21:43:12 |
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(register int i = a; i <= b; ++i)
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
using namespace std;
inline char get_char()
{
static char buf[27860], *p1=buf, *p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,27860,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
int x = 0, f = 0; char ch = get_char();
while(ch < '0'||ch > '9') {f|=(ch=='-'); ch = get_char();}
while(ch >= '0'&&ch <= '9') {x = (x<<3) + (x<<1) + (ch^48); ch = get_char();}
return f?-x:x;
}
ll key, n, tot = 0, lc;
ll a[1000001], sum[1000001];
void dfs(int k, int ans)
{
if(k > lc) return;
if(ans > key) return;
if(ans+sum[n]-sum[k-1] < key) return;
if(ans == key) {++tot; return;}
dfs(k+1, ans+a[k]);
dfs(k+1, ans);
}
int main()
{
freopen("password1.in", "r", stdin);
freopen("password1.out", "w", stdout);
n = read(), key = read(); lc = n + 1;
f(i,1,n) {a[i] = read(); sum[i] = sum[i-1]+a[i];}
dfs(1, 0);
printf("%lld\n", tot);
fclose(stdin);
fclose(stdout);
return 0;
}