At that time the game was stuck in D, did not see E. Now it seems that E is not difficult.
After the number of n is sorted, it is possible not to sort, but the order can be faster than half the time.
How many of the first half of the enumeration can be obtained and put into the map;
Then enumerate through the next half and look in the map.
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 5 Const intMAXN = -;6 LL A[MAXN], F[MAXN], S, ans;7 intN, M, K;8 9map<int, ll>CNT[MAXN];Ten One voidDfsintDintUsed, LL s,inttype) A { - if(d = =m) - { the if(Type = =0) cnt[used][s]++; - Else for(inti =0; i + used <= K; i++)if(Cnt[i].count (S-s)) ans + = cnt[i][s-s]; - return; - } +DFS (d +1, used, S, type); - if(S + a[d] <= s) DFS (d +1, used, S +a[d], type); + if(A[d] < +&& used < K && S + f[a[d]] <= s) DFS (d +1, used +1, S +F[a[d]], type); A } at - intMain () - { -f[0] = f[1] =1; - for(inti =2; I < +; i++) F[i] = f[i-1] *i; -CIN >> N >> k >>S; in for(inti =0; I < n; i++) Cin >>A[i]; -Sort (A, A +n); tom = n/2; +Dfs0,0,0,0); -m =N; theDFS (N/2,0,0,1); *cout << ans <<Endl; $ Panax Notoginseng return 0; -}
code June
Codeforces Round #297 Div.2 E (Midway meeting method)