Coloring grid with flexible number of colors and flexible number of occurrence per color
You're asking for a $k$-coloring of a grid graph (with some extra constraints on how many times each color is used).

One approach is to encode this as an instance of SAT or integer linear programming (ILP), and let a SAT/ILP solver look for a solution for you.  For instance, you could introduce zero-or-one variables $x_{r,s,t}$, where $x_{r,s,t}=1$ if row $r$ column $s$ has color $t$, and then write down constraints to capture that this is a valid coloring (i.e., $x_{r,s,t} + x_{r',s',t} \le 1$ when $(r,s)$ and $(r',s')$ are adjacent, $\sum_t x_{r,s,t} = 1$, and $\sum_{r,s} x_{r,s,t} \le i_t$), then feed it to an ILP solver.

Related (but different): Number of ways to fill a 2xN grid with M colors, Counting Colorings of a Grid.