WOJ1032-Find the Max NORM
来源:互联网 发布:数据标准化是什么意思 编辑:程序博客网 时间:2024/05/24 07:43
As you know, matrix theory is widely used in the engineering and other fields. But do you know boolean matrix? It's a most useful matrix
in the computer science. In graph theory, IC design and compiler theory, boolean matrix plays an important role.
One day Little Dragonfly has to do his homework. But one Hard problem puzzles him. Now he wants you to help him to resolve this Hard
problem. The description of the Hard problem:
Note that Boolean matrix is the matrix that each entry in it is 0 or 1. We define the NORM of the boolean matrix as follow:
NORM = the sum of all the entry in the matrix.
And define two manipulations of the matrix:
A(n) : reverse every entry of the nth row;
B(n) : reverse every entry of the nth column;
Given a boolean matrix, you can get some matrices after a series of the two manipulations. Now you have to find the Max NORM of these
matrices.
Examples:
(1) Give a 22 matrix:
0 1
1 0
The Max NORM is 4.
Because we can get a matrix
1 1
1 1
after A(1),B(2). Then the NORM is the largest.
(2) Give another 22 matrix
0 1
1 1
The Max NORM is 3.
输入格式
The input contains several cases. In the first line of each case there are two integers:mmm and nnn (1≤m≤101\le m \le 101≤m≤10,1≤n≤30001\le n \le 30001≤n≤3000). And in the following m lines there are the entries of the m×nm\times nm×n boolean matrix. Each entry is 0 or 1.
Input will be terminated by EOF.
输出格式
For each case, you should print the Max NORM in one line.
样例输入
2 20 11 02 20 11 1
样例输出
43暴力小的一维的取法 对于每种取法在大的一维取最优值
#include<stdio.h>int a[11][3001];int ans,m,n;int count(){ int i,j,tp,sum=0; for(i=0;i<n;i++){ tp=0; for(j=0;j<m;j++) if(a[j][i]) tp++; if(2*tp<m) tp=m-tp; sum+=tp; } return sum;}void solve(int t){ int j,tp; if(t<m) solve(t+1); else{ tp=count(); if(tp>ans) ans=tp; return;}if(ans==m*n)return; for(j=0;j<n;j++) a[t][j]=!a[t][j]; if(t<m) solve(t+1); else return; if(ans==m*n)return; for(j=0;j<n;j++) a[t][j]=!a[t][j]; return;}int main(){int i,j; while(scanf("%d %d",&m,&n)!=EOF){ for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); ans=0; solve(1); printf("%d\n",ans); } return 0;}
- WOJ1032-Find the Max NORM
- HDU 1594 find the max
- hdu find the max(1594)
- Max-out network--p norm
- the nuclear norm
- CSU 1317 Find the max Link
- norm和find函数用法
- 171121 Differences between the L1-norm and the L2-norm
- [Dynamic Programming]Recursion/Non-recursion to find the max number
- 杭电ACM HDU 1594 find the max
- find the N max numbers from an array
- hdu 1594 (find the max) (绝对值最大值比较大小)
- Norm
- Norm
- The MAX
- The MAX
- The MAX
- THE MAX
- 希尔排序
- 38. Count and Say —— Java
- [转]普通GPIO口模拟SPI通信协议
- HBase scan setBatch和setCaching的区别
- python里怎么终止程序的执行
- WOJ1032-Find the Max NORM
- Linux中Makefile的使用
- 快速排序
- 我以亲身经历告诉你崔廉正不是骗子
- 【SPSS】统计功能与模块对照表
- linux查看日志
- R语言下载gganimate包
- css+div总结
- json数据类型 导致(xxx).ToLowerCase isnot a function