编程介的小学生 2019-04-03 10:52 采纳率: 20.5%
浏览 163

矩阵的优化的一个算法的问题怎么实现,用C语言的程序的编程的技术的实现

Problem Description
In Matrix Science, Unit Matrix (UM) is a matrix in which the elements on diagonal are all 1, while others are all 0.
Based on Unit Matrix, we define Basic Matrix and Graceful Matrix:

1.Basic Matrix (BM), BM_i means swap the i-th rows and (i+1)-th rows in the Unit Matrix. (0 based)
2.Graceful Matrix (GM), means in every rows and every columns, there is one and only one 1, while others are all 0.

Now we also have a graceful problem, given a GM whose size is N, you need find a BM sequence. At first, the matrix is a UM, by multiplying the matrix one by one in the BM’s sequence order we can get the GM finally. You needn’t find the shortest sequence, but the sequence’s length can’t exceed the number of elements in GM.

Input
The first line contains a single integer T, indicating the number of test cases.
Each test case begins with an integer N, indicating the GM’s size.
Then N lines follow, each line contains N integers, 1 or 0, indicating the GM.
You can assume the input Matrix is always graceful.

Technical Specification

  1. 1 <= T <= 50
  2. 2 <= N <= 1000

Output
For each test case, output the case number first, then the length of the sequence T your answer will give. Then follow T integers Ai, indicating BM_Ai, the sequence. If the length is zero, just output a blank line.
Make sure your output BM_Ai never exceeds the Input N minus 1, because it doesn't make any sense.
This is a Special Judge problem, so your format should not make any mistake. You can refer to the sample output for more information.

Sample Input
3
2
1 0
0 1
2
0 1
1 0
4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0

Sample Output
Case 1: 0

Case 2: 1
0
Case 3: 2
0 2

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题