Say is given n cubes, cubes from 1 to n, each cube has a number, you have K chance to make the K number their own factorial, (natural use can be less than k chance, each cube is used up to 1 times), then find you from the N cubes to re-select any of the cubes to make Their and for S
N<25
Can know the direct use of N to enumerate the natural unbearable, we divide n numbers into two parts to calculate, the front N/2 number we enumerate they use J can get the number, and then the number of N-N/2 back to use this method, directly in the DFS enumeration at the time to determine whether s-s in the previous clock has occurred, Add up when they appear. chunked processing
1#include <iostream>2#include <algorithm>3#include <string.h>4#include <map>5#include <cstdio>6 using namespacestd;7typedefLong LongLL;8Map<ll,int>mp[ -];9LL a[ -];TenLL dp[ -]; OneLL time[1000000]; A intn,k; - LL S,ans; - voidDfsintPintK, LL s) { the if(p==n/2){ -mp[k][s]++; -}Else{ -DFS (p+1, k,s); + if(s+a[p]<=s) DFS (p+1, k,s+a[p]); - if(k +1<=k && a[p]<= -&& S+dp[a[p]] <=s) DFS (p+1, K +1, s+Dp[a[p]]); + } A } at voidDFS1 (intPintK, LL s) { - if(p==N) { - for(inti =0; i+k<=k; i++) - if(Mp[i].count (S-s) >0) ans+=mp[i][s-s]; -}Else{ -DFS1 (p+1, k,s); in if(s+a[p]<=s) DFS1 (p+1, k,s+a[p]); - if(k +1<=k && a[p]<= -&& s+dp[a[p]]<=s) DFS1 (p+1, K +1, s+Dp[a[p]]); to } + } - intMain () the { * $ Panax Notoginsengdp[0]=1; - for(LL i=1; i<= -; i++) dp[i]=dp[i-1]*i; thecn1=0; +scanf"%d%d%i64d",&n,&k,&S); A for(intI=0; i<n; i++) thescanf"%i64d",&a[i]); +Dfs0,0,0); -DFS1 (n/2,0,0); $printf"%i64d\n", ans); $ return 0; -}
Codeforces E-anya and Cubes block violence search