output_description: Print the number of minimum times the bar needs to be cut so that every block
  after the cuts has K or less white squares.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W K
      S_{1,1}S_{1,2}...S_{1,W}
      :
      S_{H,1}S_{H,2}...S_{H,W}
attempt: def e_dividing_chocolate():
      # 参考: https://note.com/tanon_cp/n/ne70a87d249ed
      H, W, K = [int(i) for i in input().split()]
      Choco = [list(input()) for _ in range(H)]
  
      # 左上のマスを (0, 0)、右下のマスを (col, row) としたとき、2 点で張られる
      # 長方形区間の内部に含まれる 1 (ホワイトチョコレートのマス) の数を累積和で管理
      cumsum = [[0] * W for _ in range(H)]
      for row in range(H):
          for col in range(W):
              if Choco[row][col] == "1":
                  cumsum[row][col] += 1
              if row != 0:
                  cumsum[row][col] += cumsum[row - 1][col]
              if col != 0:
                  cumsum[row][col] += cumsum[row][col - 1]
              if row != 0 and col != 0:
                  cumsum[row][col] -= cumsum[row - 1][col - 1]
  
      def count_white_chocolate(x1, y1, x2, y2):
          """左上のマスを (x1, y1)、右下のマスを (x2, y2) としたとき、2 点で張られる
          長方形区間の内部に含まれる 1 (ホワイトチョコレートのマス) の数"""
          ret = cumsum[y2][x2]
          if x1 != 0:
              ret -= cumsum[y2][x1 - 1]
          if y1 != 0:
              ret -= cumsum[y1 - 1][x2]
          if x1 != 0 and y1 != 0:
              ret += cumsum[y1 - 1][x1 - 1]
          return ret
  
      ans = (H - 1) + (W - 1)  # 1 マスに分けてしまえば要求を満たすことは保証されている
      # 横の切り方は全探索する
      for bits in range(1 << (H - 1)):
          count = 0  # 何回チョコに切り込みを入れたか？
  
          # 横の切り込みをどこに入れるかを決める
          cut_row = []
          cut_flag = format(bits, "b")[::-1]
          for k, flag in enumerate(cut_flag):
              if flag == "1":
                  count += 1
                  # k 行目と (k+1) 行目の間を切るとき、長方形区間の最下段は k 行目
                  cut_row.append(k)
          cut_row.append(H - 1)  # チョコ全体での最下段も加えておく
  
          # col1-col2 の間は切り込みを入れないでもホワイトチョコが K 個以下である
          col1 = 0
          for col2 in range(W - 1):
              row1 = 0
              for row2 in cut_row:
                  if count_white_chocolate(col1, row1, col2, row2) > K:
                      count = float(
                          "inf"
                      )  # 現在の横の切り込みの入れ方では要求を満たせない
  
                  # col2 列目と col2+1 列目の間に縦に切り込みを入れなければならない
                  if (
                      count_white_chocolate(col1, row1, col2, row2) <= K
                      and count_white_chocolate(col1, row1, col2 + 1, row2) > K
                  ):
                      # ここで縦に切り込みを入れ、右の区画へ移動
                      count += 1
                      col1 = col2 + 1
                      break
                  row1 = row2 + 1  # 下の区画へ移動
  
          # 最後に縦に切り込みを入れた区画の右の区画はまだ調べていないので、調べる
          row1 = 0
          for row2 in cut_row:
              if count_white_chocolate(col1, row1, W - 1, row2) > K:
                  count = float("inf")
              row1 = row2 + 1
  
          ans = min(ans, count)
      return ans
  
  
  print(e_dividing_chocolate())
  
problem_description: Statement
  
  We have a chocolate bar partitioned into H horizontal rows and W vertical
  columns of squares.
  
  The square (i, j) at the i-th row from the top and the j-th column from the
  left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
  
  We will cut the bar some number of times to divide it into some number of
  blocks. In each cut, we cut the whole bar by a line running along some
  boundaries of squares from end to end of the bar.
  
  How many times do we need to cut the bar so that every block after the cuts
  has K or less white squares?
samples: [{"input": "3 5 4\n    11100\n    10001\n    00111", "output": "2\n    \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n![Figure](https://img.atcoder.jp/ghi/ac90dd542639c04402125403b1c319d7.png)\n\n* * *"}, {"input": "3 5 8\n    11100\n    10001\n    00111", "output": "0\n    \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n    1110010010\n    1000101110\n    0011101001\n    1101000111", "output": "3"}]