编程介的小学生 2017-04-10 13:23 采纳率: 20.5%
浏览 805
已采纳

Ball Again

After the ball held on October, 2004 (on that time, we are enjoying our last ZOJ Monthly Contest), all the attendants have had more friends. Thanks for your help on arranging them on the ball last time. But now a new problem comes, and puzzled me a lot. I have to come to ask for your help again.

The new friends are all busy in attending meetings. If there are M (M >= 3) persons sitting in a circle and everyone is a friend of his adjacent person, then a meeting will be held for these M people. Therefore, there will be a lot of meetings among them, which makes me busy in preparing the dining table for them.

The dining tables all have fixed size and each can accommodate K seats. I wanted to use these tables without any space left during each meeting. For example, if 6 persons have a meeting at a time, the type of table with parameter K = 1, 2, 3, 6 will meet our requirement and K = 4 will not bacause it will leave 2 seats vacant as you have to use two tables for the meeting.

Now I want to know, what's the maximum value of K.

Input

There are several test cases. Each case starts with a positive integer N (3 < N <= 100), denotes the number of persons coming back from the ball. Then N lines follows. Each line contains N integers either '1' or '0', with exactly one space between adjacent. A '1' in the ith row and jth column represents that a[j] is a friend of a[i] and a '0' means not.

Proceed the cases until N = 0, which should not be proceeded.

Output

One positive integer K on a single line for each case, which means the maximum size of dining table.

Sample Input

4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
6
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0

Sample Output

1
2

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥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,如何解決?