Skip to content

Instantly share code, notes, and snippets.

@zeptometer
Created October 26, 2010 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeptometer/647143 to your computer and use it in GitHub Desktop.
Save zeptometer/647143 to your computer and use it in GitHub Desktop.
aoj0525
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int row,col;
int[] cols;
int cnt_min = 10*10000;
row = scn.nextInt();
col = scn.nextInt();
cols = new int[col];
for(int i=0; i<row; i++) for(int j=0; j<col; j++)
cols[j] = (cols[j]<<1)+scn.nextInt();
for(int i=0; i<1<<(row-1); i++){
int cnt=0;
for(int column : cols){
int tmp=0;
column=column^i;
for(int j=0; j<row; j++,column >>= 1)
if(column&1 == 0) tmp++;
cnt += (tmp<(row-tmp))?tmp:(row-tmp);
}
cnt_min = (cnt<cnt_min)?cnt:cnt_min;
}
System.out.println(row*col-cnt_min);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment