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: from collections import Counter
  
  
  H, W, K = [int(x) for x in input().split()]
  grid = [[int(x) for x in input()] for r in range(H)]
  
  best = float("inf")
  for cuts in range(2**H):
      # Initialize numCuts to the number of horizontal cuts
      hCutIndices = [r for r in range(H) if (1 << r) & cuts]
      numCuts = len(hCutIndices)
  
      # The count for each horizontal cut since last cut
      cumulativeCount = Counter()
  
      for c in range(W):
          # The count for each horizontal cut for this column
          columnCount = {}
          curr = 0
          for r in range(H):
              curr += grid[r][c]
              if (1 << r) & cuts or r == H - 1:  # Note: last row is always a cut
                  columnCount[r] = curr
                  curr = 0
  
          # Add column count to cumulative count if possible
          if all(cumulativeCount[r] + columnCount[r] <= K for r in columnCount):
              for r in columnCount:
                  cumulativeCount[r] += columnCount[r]
          else:
              # Cut and reset cumulative count to this column
              numCuts += 1
              cumulativeCount = columnCount
              # If counts within just the column is no good, the current set of horizontal cuts is impossible
              if any(counts > K for r, counts in columnCount.items()):
                  numCuts = float("inf")
                  break
      best = min(best, numCuts)
  
  print(best)
  
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"}]