본문 바로가기
PS/백준

[백준] 램프 - Java 1034

by 진꿈청 2024. 10. 10.
public class BOJ1034 {
    /**
     * 14 3
     * 001
     * 101
     * 001
     * 000
     * 111
     * 001
     * 101
     * 111
     * 110
     * 000
     * 111
     * 010
     * 110
     * 001
     * 6
     */
    static String[] grid;
    static int N;
    static int M;
    static int K;
    static int max;
    static int result = 0;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        N = Integer.parseInt(st.nextToken());
        M = Integer.parseInt(st.nextToken());
        grid = new String[N];
        int[] rampOff = new int[N];
        for(int i = 0; i < N; i++){
            String num = br.readLine();
            for(int j = 0; j < M; j++){
                if(num.charAt(j) == '0'){
                    rampOff[i]++;
                }
                grid[i] = num;
            }
        }
        K = Integer.parseInt(br.readLine());
        int max = 0;
        for(int i = 0; i < N; i++){
            if(rampOff[i] <= K && (K - rampOff[i]) % 2 == 0){
                int count = 1;
                for(int j = 0; j < N; j++){
                    if(i != j){
                        if(grid[i].equals(grid[j])){
                            count++;
                        }
                    }
                }
                max = Math.max(count, max);
            }
        }
        System.out.println(max);
    }
}