Number of sequences with a given constraint

Revision en4, by typedeftemplate, 2019-09-24 20:13:33

Suppose you want to construct sequences from the restricted alphabet {1, 2, 3, 4, 5, 6}. However, you cannot place the number i (i = 1, 2, 3, ... 6) more than A[i] times consecutively, where A is a given array. Given the sequence length 1 <= N <= 10^5 and the array A with 1 <= A[i] <= 50, how many possible sequences are possible?

For example, suppose A = {1, 2, 1, 2, 1, 2} and N = 2. In this case, there can only be one consecutive 1, two consecutive 2's, one consecutive 3, etc. So in this example, something like "11" would be invalid, but something like "12" or "22" would be valid. It turns out that there are actually 33 possible sequences in this case (namely, two-digit sequence except for "11", "33", and "55").

I was wondering how I can solve this problem? Initially, I tried to use a DP approach, but I have been thinking there might be a clever combinatoric strategy. Like, in the example I showed above, it's pretty quick to just do complementary counting. It gets really messy when I try to work it out for larger cases though. I've also tried to use inclusion-exclusion and got nowhere.

Another thing I noted is that A[i] is pretty small, but I wasn't able to get anywhere with that observation.

I would greatly appreciate some help in solving this problem. It might just be a really easy combinatorics problem. I am really bad at that topic, so I wouldn't be surprised if is just something I am not seeing.

Thanks.

Tags #combinatorics, #dp, #counting

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English typedeftemplate 2019-09-24 20:13:33 2 Tiny change: 'nsecutive 1, etc. So ' -> 'nsecutive 3, etc. So '
en3 English typedeftemplate 2019-09-24 19:02:05 151
en2 English typedeftemplate 2019-09-24 18:56:55 60
en1 English typedeftemplate 2019-09-24 18:56:19 1280 Initial revision (published)