Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://codeforces.com/problemset/problem/525/E
- #include<bits/stdc++.h>
- using namespace std;
- #define si(n) scanf("%d",&n)
- #define ll long long
- #define MAX 30
- int a[MAX],n,K;
- ll S,fact[MAX],ans=0;
- unordered_map<ll,int>M[30];
- void go(int pos,int k,ll s,int limit,bool flag)
- {
- //cout<<pos<<' '<<k<<' '<<s<<' '<<limit<<' '<<flag<<endl;
- if(pos>limit){
- if(flag){
- for(int i=0;i<=K-k;i++)
- ans+=M[i][S-s];
- }
- else M[k][s]++;
- return ;
- }
- if(a[pos]<19)go(pos+1,k+1,s+fact[a[pos]],limit,flag);
- go(pos+1,k,s+a[pos],limit,flag);
- go(pos+1,k,s,limit,flag);
- }
- int main()
- {
- //freopen("input.txt","r",stdin);
- int i,j;
- fact[0]=1;
- for(i=1;i<=18;i++)fact[i]=fact[i-1]*i;
- si(n);si(K);scanf("%lld",&S);
- for(i=1;i<=n;i++)si(a[i]);
- go(1,0,0,n/2,0);
- go(n/2 +1,0,0,n,1);
- printf("%lld\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement