Language: Java

import java.util.*;
import java.io.*;
import java.text.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        
        int h = sc.nextInt();
        int w = sc.nextInt();
        int alwed = sc.nextInt();
        
        
        int count =0, min=Integer.MAX_VALUE;
        int[][] dp_sum = new int[h][w];
        
        String input = sc.next();
        
        dp_sum[0][0] = input.charAt(0)-48;
        for(int j=1; j<w; j++){
            dp_sum[0][j] = dp_sum[0][j-1] + input.charAt(j)-48;
        }
    	for(int i=1; i<h; i++){
    	    input = sc.next();
    	    dp_sum[i][0] = input.charAt(0)-48;
    		for(int j=1; j<w; j++){
                dp_sum[i][j] = dp_sum[i][j-1] + input.charAt(j)-48;
    		}
    	}
    	
    	for(int i=1; i<h; i++){
    		for(int j=0; j<w; j++){
                dp_sum[i][j] += dp_sum[i-1][j];
    		}
    	}
    	/*for(int i=0; i<h; i++){
    		for(int j=0; j<w; j++){
                System.out.print(dp_sum[i][j]+" ");
    		}
    		System.out.println();
    	}*/
        
        int[] break_yoko_l = new int[h];
        int count_yoko_break=0;
    	for(int bit=0; bit < (1<<(h-1)); bit++){
    	    count=0;
    	    count_yoko_break=0;
    	    for(int i=0; i<h-1; i++){
                if(bit&(1<<i) > 0){
                    break_yoko_l[count_yoko_break] = i;
                    count_yoko_break++;
                }
            }
            for(int i=count_yoko_break; i<h; i++){
                break_yoko_l[count_yoko_break] = h-1;
            }
            
            //count_yoko_break=割ったあとの横長個数-1。break___[]割る上のいち
            
            int lastbreak=-1;
            loop1: for(int i=0; i<w; i++){
                if(dp_sum[break_yoko_l[0]][i] > alwed){
                    lastbreak = i-1;
                    count++;
                    break;
                }
                for(int j=1; j<=count_yoko_break; j++){
                    if((dp_sum[break_yoko_l[j]][i] - dp_sum[break_yoko_l[j-1]][i]) > alwed){
                        lastbreak = i-1;
                        count++;
                        break loop1;
                    }
                }
            }
            while(true){
                loop2: for(int i=lastbreak+1; i<w; i++){
                    
                    if((dp_sum[break_yoko_l[0]][i] - dp_sum[break_yoko_l[0]][lastbreak]) > alwed){
                        lastbreak = i-1;
                        count++;
                        break;
                    }
                    for(int j=1; j<=count_yoko_break; j++){
                        if((dp_sum[break_yoko_l[j]][i] - dp_sum[break_yoko_l[j-1]][i] - dp_sum[break_yoko_l[j]][lastbreak] + dp_sum[break_yoko_l[j-1]][lastbreak]) > alwed){
                        lastbreak = i-1;
                        count++;
                        break loop1;
                    }
                    }
                }
                break;
            }
            if(count<min) min =count;
    	}
    	System.out.println(min);
        
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Compiler output:
Main.java:49: error: bad operand types for binary operator '&'
                if(bit&(1<<i) > 0){
                      ^
  first type:  int
  second type: boolean
Main.java:87: error: undefined label: loop1
                        break loop1;
                        ^
2 errors