Codeforces E-anya and Cubes block violence search

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.