Language: C++

#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    float _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//     cout << fixed << setprecision(15);

    int h,w,k, cnt = 0; cin >> h >> w >> k;
    vii grid(h, vi(w));
    char ch;
    rep(i,h) rep(j,w) {
        cin >> ch;
        if(ch == '1') {
            grid[i][j] = 1;
            ++cnt;
        }
        else grid[i][j] = 0;
    }
//  許容の方がでかい
    if(k >= cnt) {
        cout << 0 << '\n';
        return 0;
    }
    // 累積和
    vii wh(h+1, vi(w+1));
    rep(i,h)rep(j,w) wh[i+1][j+1] += wh[i+1][j] + (grid[i][j]? 1 : 0);
    rep(i,h)rep(j,w) wh[i+1][j+1] += wh[i][j+1];

//    hの方の分割を全探索
    int answer = inf;
    for(int bit = (1<<h-1); bit < (1<<h); ++bit) {  // bitが立ってるところがブロックの下限
//        int Bit = bit | (1<<h-1);  // 最下段のブロックの下限は常に最下段の列
        bool Cant = 0;
        cnt = [&](){int ret = 0; for(int i = 0; i < h; ++i) if((Bit>>i)&1) ++ret; return ret-1;}();

        int up = 0, l = 0, down = 0, r = 0;
        for(int j = 0; j < w; ++j) {
            r = j;
            // 含めるか判定
            bool can = 1;
            up = 0;
            for(int i = 0; i < h-1; ++i) {
                for(int o = up; o < h; ++o) if((Bit>>o)&1) {  // 境界を探す
                    down = o;
                    break;
                }
                // そのブロックが条件を満たすか
                if(wh[down+1][r+1]-wh[down+1][l]-wh[up][r+1]+wh[up][l] > k) can = 0;
//                if(Bit == (0 | (1<<h-1))) debug(wh[down+1][r+1]-wh[down+1][l]-wh[up][r+1]+wh[up][l]); // DEBUG
                // up = down
                up = down+1;
            }

            // j列をブロックに含めないか
            if(!can) {
                ++cnt;
                l = r;  // 含められなかった列が次のブロックの左端になる
            }
            if(!can && r==l && j == w-1) Cant = 1;
        }
//        cout << (Cant? "FALSE" : "TRUE") << '\n';
//        if(Cant) continue;
//        debug(cnt);
        chmin(answer, cnt);
//        debug(answer);
    }

    cout << answer << '\n';

    // printf("ExecutionTime: %d /ms\n",(double)((clock()-_StartTime_)/CLOCKS_PER_SEC*1000));
}

Compiler output:
a.cc: In lambda function:
a.cc:74:65: error: 'Bit' was not declared in this scope; did you mean 'bit'?
   74 |         cnt = [&](){int ret = 0; for(int i = 0; i < h; ++i) if((Bit>>i)&1) ++ret; return ret-1;}();
      |                                                                 ^~~
      |                                                                 bit
a.cc: In function 'int main()':
a.cc:83:49: error: 'Bit' was not declared in this scope; did you mean 'bit'?
   83 |                 for(int o = up; o < h; ++o) if((Bit>>o)&1) {  // 境界を探す
      |                                                 ^~~
      |                                                 bit