Counting binary strings that have atmost k consecutive 0's I know how to count how many binary strings with length n and having exactly k 0's are there but i am not able to find a way to count the number of binary strings that have exactly x 0's and y 1's and uses at most k1 consecutive 0's and k2 consecutive 1's.
Here is how I approach I can enumurate through all possible binary string that uses exactly x 0's and y 1's and subtract from those that have more than k1 consecutive 0's and k2 consecutive 1's but how do  I find binary strings that have more than k1 consecutive 0's and k2 consecutive 1's.
Any other approach to solve the same problem.
 A: A generating function is straightforward to compute using the Goulden-Jackson cluster method (which is designed to solve exactly this kind of problem).  A canonical reference is [Noonan-Zeilberger 1998]; additionally, [Kupin-Yuster 1998] works out an example problem in exactly the generality you're looking for.  The calculation itself is easy; the post is long as I include a brief exposition of the method.
We're given a set $\mathcal{B}$ of "bad words" over an alphabet $\mathcal{A}$; we'll take $\mathcal{A}=\{0,1\}$.  We assume no bad word contains another.  We want to enumerate strings containing no bad words according to their weight; the weight of a string $s$ is $w(s)=x^i y^j$, where $i$ is the number of $0$'s in the string and $j$ is the number of $1$'s.  The weight enumerator of a set $S$ of strings is the sum of $w(s)$ over all $s\in S$.
A marked string is a string $s$ together with a collection $S$ of some instances of bad words contained in $s$; the weight of a marked string is $(-1)^{|S|} w(s)$.
A cluster is a string composed of an overlapping set of bad words; see the references for the precise definition.  (In your application, the bad words are $0^{k_1+1}$ and $1^{k_2+1}$, so the only clusters have the form $0^{> k_1}$ or $1^{> k_2}$.)
Define $\mathcal{C}(x,y)$ to be the weight enumerator of all marked clusters; we have $\displaystyle\mathcal{C}(x,y) = \sum_{b\in\mathcal{B}}\mathcal{C}_b(x,y),$
where $\mathcal{C}_b$ is the weight enumerator of marked clusters in which the first bad word is $b$.
The Goulden-Jackson method rests on two observations.  First, it's easy to write down a system of linear equations which determine the marked cluster enumerators, based on the overlaps among the bad words.  Second, the weight enumerator for strings containing no bad words is given by
$$\mathcal{G}(x,y) = \frac{1}{1-(x+y)-\mathcal{C}(x,y)}.$$
To compute the marked cluster enumerators, we have the following equations for each $b\in\mathcal{B}$:
$$\mathcal{C}_b = -w(b) - \sum_{b'\in\mathcal{B}}\sum_r w(b_r)\mathcal{C}_{b'}$$
where $b_r$ denotes the $r$-long prefix of $b$, and $r$ ranges over values such that $b$ is the concatenation of $b_r$ with a prefix of $b'$.  In the present example, the bad words overlap with themselves but not with each other, so the equations separate.  In particular, for $b=0^{k_1+1}$, we get
$$\mathcal{C}_b(x,y)=-x^{k_1+1} - \sum_{r=0}^{k_1} x^r \mathcal{C}_b(x,y),$$
which implies
$$\mathcal{C}_b(x,y)= -\frac{x^{k_1+1}(1-x)}{1-x^{k_1+1}}.$$
You get an analogous formula for $b=1^{k_2+1}$.  Thus, according to Goulden-Jackson, the generating function for strings containing neither $0^{k_1+1}$ nor $1^{k_2+1}$ is given by
$$\mathcal{G}(x,y)=\frac{1}{1-(x+y)+\frac{x^{k_1+1}(1-x)}{1-x^{k_1+1}}+\frac{y^{k_2+1}(1-y)}{1-y^{k_2+1}}}.$$
This answer agrees with the one provided by @MarkusScheuer.
