Count the number of arrays

Count the number of arrays of length N having the sum of elements equal to S and the bitwise OR of all the element in the array should be equal to K.
N,S,K <= 5000
I have a DP solution which involve 3 states and its complexity is too high. Can anyone tell me a better way of solving this task.