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)