Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 문자열다루기
- 다이나믹프로그래밍
- activity
- 이분탐색
- 프로그래머스
- 운영체제
- 세그먼트트리
- Android
- 분할정복
- dfs
- 백준
- 코딩
- 완전탐색
- 배열
- 코틀린
- 알고리즘
- 카카오블라인드
- 자바
- BOJ
- 코딩테스트
- 트리
- 동적계획법
- BFS
- 안드로이드
- 문자열
- 생명주기
- component
- GIT
- 그래프
- 스택
Archives
- Today
- Total
HS_development_log
백준 1034번 - 램프 / Java 본문
반응형
1. 문제
2. 알고리즘
-
스위치 조작은 하나의 열을 통째로 바꿔버리므로 초기 상태가 다른 행은 조작 횟수와 상관없이 같아질 수 없다.
-
따라서 스위치 조작을 k번했을때 모두 1로바꿀수 있는 행 + 같은 행의 개수가 가장 많은 행의 개수
-
k번 조작했을때 모두 1로 바꿀 수 있는 행은 (0의개수%2==k%2) && 0의개수<=k 이다.
3. 코드
/**
* 2020.07.24
* 백준 1034 : 램프
* DevHyeonseong
*/
import java.util.Scanner;
public class BOJ1034 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
scan.nextLine();
int[][] table = new int[n][m];
String[] temp = new String[n];
for(int i=0;i<n;i++){
temp[i] = scan.nextLine();
for(int j=0;j<m;j++){
table[i][j] = Integer.parseInt(temp[i].charAt(j)+"");
}
}
int k = scan.nextInt();
boolean[] check = new boolean[n];
int max = 0;
for(int i=0;i<n;i++){
int cnt = 0;
for(int j=0;j<m;j++){
if(table[i][j]==0){
cnt++;
}
}
if((cnt%2==k%2)&&cnt<=k){ // k번 조작해서 조건에 맞는 행이 나오는지
check[i]=true;
}
}
for(int i=0;i<n;i++){
if(check[i]){ // 조건에 맞는 행만
int cnt = 0;
for(int j=0;j<n;j++){
if(temp[i].equals(temp[j])){ // 초기상태가 같은 행의 개수를 센다
cnt++;
}
}
if(max < cnt){
max = cnt;
}
}
}
System.out.println(max);
}
}
끝.
반응형