Firstly, note that the number of blocks of each color you have is a complete red herring, since 10 ^ 100> N always. Thus, the number of blocks of each color is almost infinite.
Now note that in each position p(if there is a valid configuration that does not contain spaces, etc.). There should be a color block c. There is a len[c]way that the block must lie, so he is still on this position p.
- (N/2, ), b a . , ways(i), i ( ways(0)=1). ways(b)*ways(a). ways(i).
N/2, , ceil(log(N)). , N/2, N/2-750 N/2-750, 750 - , . 750*ceil(log(N)) ( - ) .
, , , memoisation, .
Python ( ):
T = int(raw_input())
for case in xrange(T):
C = int(raw_input())
lengths = map(int, raw_input().split())
minlength = min(lengths)
n = int(raw_input())
memoise = {}
memoise[0] = 1
for length in xrange(1, minlength):
memoise[length] = 0
def solve(n):
global memoise
if n in memoise:
return memoise[n]
ans = 0
for i in xrange(C):
if lengths[i] > n:
continue
if lengths[i] == n:
ans += 1
ans %= 100000007
continue
for j in xrange(0, lengths[i]):
b = n/2-lengths[i]+j
a = n-(n/2+j)
if b < 0 or a < 0:
continue
ans += solve(b)*solve(a)
ans %= 100000007
memoise[n] = ans
return memoise[n]
solve(n)
print "Case %d: %d" % (case+1, memoise[n])
. , , 20- , ++ somesuch.
EDIT: N = 10^15 750 , memoise 60000 , , solve(n) .