#!/usr/bin/ python3.8

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

import itertools

H, W, K = list(map(int, readline().split()))

S = [list(map(int, line.rstrip().decode())) for line in readlines()]

# transpose

S = tuple(itertools.chain(*list(zip(*S))))



INF = 10 ** 9





def solve(s):

    dp = list(S)

    for j in range(H - 1):

        if s & (1 << j):

            for n in range(0, H * W, H):

                dp[n + j + 1] += dp[n + j]

    cut = H - 1 - bin(s).count('1')

    for n in range(0, H * W, H):

        if any(dp[n + i] > K for i in range(H)):

            return INF

        if n + H == H * W:

            return cut

        if any(dp[n + i] + dp[n + i + H] > K for i in range(H)):

            cut += 1

            continue

        for i in range(H):

            dp[n + i + H] += dp[n + i]

    return cut





answer = min(solve(s) for s in range(1 << (H - 1)))

print(answer)

import sys

import numpy as np

import numba

from numba import njit

from numba.types import Omitted

i4 = numba.int32

i8 = numba.int64



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



@njit((i8[:, :], i8), cache=True)

def main(S, K):

    H, W = S.shape

    ans = H + W + 100

    for s in range(1 << H - 1):

        cost = 0

        T = S.copy()

        for i in range(H - 1):

            if s & 1 << i:

                T[i + 1] += T[i]

            else:

                cost += 1

        if np.any(T > K):

            continue

        cumsum = np.zeros(H, np.int64)

        for w in range(W):

            if np.any(cumsum + T[:, w] > K):

                cumsum[:] = 0

                cost += 1

            cumsum += T[:, w]

        ans = min(ans, cost)

    return ans



H, W, K = list(map(int, readline().split()))

S = np.empty((H, W), np.int64)

for h in range(H):

    S[h] = np.array(list(readline().rstrip().decode()))



print((main(S, K)))
#!/usr/bin/ python3.8
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

H, W, K = list(map(int, readline().split()))
S = [list(map(int, line.rstrip().decode())) for line in readlines()]
# transpose
S = tuple(itertools.chain(*list(zip(*S))))
INF = 10**9


def solve(s):
    dp = list(S)
    for j in range(H - 1):
        if s & (1 << j):
            for n in range(0, H * W, H):
                dp[n + j + 1] += dp[n + j]
    cut = H - 1 - bin(s).count("1")
    for n in range(0, H * W, H):
        if any(dp[n + i] > K for i in range(H)):
            return INF
        if n + H == H * W:
            return cut
        if any(dp[n + i] + dp[n + i + H] > K for i in range(H)):
            cut += 1
            continue
        for i in range(H):
            dp[n + i + H] += dp[n + i]
    return cut


answer = min(solve(s) for s in range(1 << (H - 1)))
print(answer)

import sys
import numpy as np
import numba
from numba import njit
from numba.types import Omitted

i4 = numba.int32
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8[:, :], i8), cache=True)
def main(S, K):
    H, W = S.shape
    ans = H + W + 100
    for s in range(1 << H - 1):
        cost = 0
        T = S.copy()
        for i in range(H - 1):
            if s & 1 << i:
                T[i + 1] += T[i]
            else:
                cost += 1
        if np.any(T > K):
            continue
        cumsum = np.zeros(H, np.int64)
        for w in range(W):
            if np.any(cumsum + T[:, w] > K):
                cumsum[:] = 0
                cost += 1
            cumsum += T[:, w]
        ans = min(ans, cost)
    return ans


H, W, K = list(map(int, readline().split()))
S = np.empty((H, W), np.int64)
for h in range(H):
    S[h] = np.array(list(readline().rstrip().decode()))
print((main(S, K)))

-#!/usr/bin/ python3.8 +import numpy as np +import numba +from numba import njit +from numba.types import Omitted +i4 = numba.int32 +i8 = numba.int64 -import itertools + + +@njit((i8[:, :], i8), cache=True) +def main(S, K): +    H, W = S.shape +    ans = H + W + 100 +    for s in range(1 << H - 1): +        cost = 0 +        T = S.copy() +        for i in range(H - 1): +            if s & 1 << i: +                T[i + 1] += T[i] +            else: +                cost += 1 +        if np.any(T > K): +            continue +        cumsum = np.zeros(H, np.int64) +        for w in range(W): +            if np.any(cumsum + T[:, w] > K): +                cumsum[:] = 0 +                cost += 1 +            cumsum += T[:, w] +        ans = min(ans, cost) +    return ans + -S = [list(map(int, line.rstrip().decode())) for line in readlines()] -# transpose -S = tuple(itertools.chain(*list(zip(*S)))) -INF = 10**9 - - -def solve(s): -    dp = list(S) -    for j in range(H - 1): -        if s & (1 << j): -            for n in range(0, H * W, H): -                dp[n + j + 1] += dp[n + j] -    cut = H - 1 - bin(s).count("1") -    for n in range(0, H * W, H): -        if any(dp[n + i] > K for i in range(H)): -            return INF -        if n + H == H * W: -            return cut -        if any(dp[n + i] + dp[n + i + H] > K for i in range(H)): -            cut += 1 -            continue -        for i in range(H): -            dp[n + i + H] += dp[n + i] -    return cut - - -answer = min(solve(s) for s in range(1 << (H - 1))) -print(answer) +S = np.empty((H, W), np.int64) +for h in range(H): +    S[h] = np.array(list(readline().rstrip().decode())) +print((main(S, K)))