encoding a vector



Hi,

i need to encode a integer vector as some integer.

v := [ a_1,...,a_n ] , a_i \in {0,n-1}

There is a condition v holds :

a_1+...+a_n <= n^2/4 (1)

I could do it with a base-n-code, but I am looking
for something more efficient, maybe by exploiting (1).
By efficient I mean, that it should fit in a 64bit word for n <= ~20.
A constraint is, that it has to be incremental updateable.


Any ideas or keywords are well appreciated.

muede
.