编程介的小学生 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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度