编程介的小学生 2020-02-08 11:49 采纳率: 20.5%
浏览 220

swap 交换算法的实现

Problem Description
There's a matrix of n rows and m columns whose elements are either 0 or 1.
If an element is 0, it is located at the i-th row and j-th column, there is at least one 1 is located at the i-th row and k-th (k < j) column, and at least one 1 is located at the i-th row and r-th(r > j) column, this element is called Cup.
You can swap any two rows and any two columns of the matrix. You can do this infinite times, to minimize the number of Cups.

Input
Multiple test cases (no more than 50), ended with EOF.
The 1st line of each test case contains two integers n and m (3 ≤ n ≤ 10, 3 ≤ m ≤ 25), the number of rows and the number of columns of the matrix.
Then following n lines, each line has m space-separated 0 or 1, indicating the original configuration of the matrix.

Output
For each test case output a number in one line, indicating the number of minimum Cups can be obtained after the swapping operations.

Sample Input
3 3
1 1 0
1 0 1
0 1 1

Sample Output
1

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 21:18
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容