SRM 508 DIV1 500pt (DP)

Source: Internet
Author: User

Topic description

Given a sequence of size n (n<=10) R, you need to calculate the number of sequences A0, A1, ..., AN-1, require a sequence to meet A0 + A1 + ... + AN-1 = A0 | A1 | ... | AN-1 (0<=ai<=r[i])

Exercises

The number of n as a binary, if the number of n is required and equal to the number of N or value, then for each bit of n number, there may be a maximum of 1, because more than one will produce a carry.

Because number I if the current bit is placed 0, but the current bit of r[i] is 1, then the position can be placed at will, there is no limit, so we can use dp[i][j] to indicate in the first bit, the current state is J of the number of conforming schemes (J Binary 1 means that the number of places is not limited, Otherwise there is a limit), with the memory of the search is very good to achieve ~ ~

Code:

1 #defineMOD 1000000009;2ll dp[ $][1111];3Vector<ll>R;4 intN;5ll DP (intIintmask)6 {7     if(i = =-1)return 1;8ll &ret =Dp[i][mask];9     if(ret!=-1)returnret;Tenret=0; One     intNext =Mask; A      for(intt =0; T < N; t++) -         if(R[t] & (1LL <<i)) -Next |= (1<<t); theRET + = DP (i-1, next); -ret%=MOD; -      for(intt =0; T < N; t++) -         if(Mask & (1<<t)) +         { -RET + = DP (i-1, next); +RET%=MOD; A         } at         Else if(R[t] & (1LL <<i)) -         { -RET + = DP (i-1, Next ^ (1<<t)); -RET%=MOD; -         } -     returnret; in } - classYetanotherorproblem to { +  Public: -     intCountsequences (vector<Long Long>R) the     { *n =r.size (); $R =R;Panax NotoginsengMemset (DP,-1,sizeof(DP)); -         returnDP ( -,0); the     } +};

SRM 508 DIV1 500pt (DP)

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.