列表

详情


NC219648. RunningRoutes

描述

The administrators at Polygonal School want to increase enrollment, but they are unsure if their gym can support having more students. Unlike a normal, boring, rectangular gym, the gym floor at Polygonal is a regular -sided polygon! They affectionately refer to the polygon as  .

The coach has drawn several running paths on the floor of the gym. Each running path is a straight line segment connecting two distinct vertices of  . During gym class, the coach assigns each student a different running path, and the student then runs back and forth along their assigned path throughout the class period. The coach does not want students to collide, so each student's path must not intersect any other student's path. Two paths intersect if they share a common point (including an endpoint).

Given a description of the running paths in  , compute the maximum number of students that can run in gym class simultaneously.



Figure H.1: Illustrations of the two sample inputs, with possible solutions highlighted in thick red lines. Solid black lines represent running paths that are not assigned to a student, and dashed black lines are used to show the boundary of  in places where no running path exists.

输入描述

The first line contains an integer , the number of vertices in  . (The vertices are numbered in increasing order around  .) Then follows  lines of  integers each, representing a  symmetric binary matrix which we'll call  . The -th integer on the -th line  is  if a running path exists between vertices  and  of the polygon, and  otherwise. It is guaranteed that for all  and .

输出描述

Print the maximum number of students that can be assigned to run simultaneously on the running paths, given the above constraints.

示例1

输入:

3
0 1 1
1 0 1
1 1 0

输出:

1

示例2

输入:

6
0 0 0 1 0 0
0 0 0 0 1 1
0 0 0 0 1 1
1 0 0 0 0 0
0 1 1 0 0 0
0 1 1 0 0 0

输出:

2

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 44ms, 内存消耗: 3284K, 提交时间: 2021-03-22 11:34:55

#include<bits/stdc++.h>
#define For(i,a,b)for(int i=a;i<=b;i++)
using namespace std;
int n,len,a[600][600],f[600][600];
int main(){
	scanf("%d",&n);
	For(i,1,n)For(j,1,n)scanf("%d",&a[i][j]);
	For(t,1,n-1)For(i,1,n-t)For(k,i,i+t)f[i][i+t]=max(f[i][i+t],f[i+1][k-1]+f[k+1][i+t]+a[i][k]);
	return printf("%d\n",f[1][n]),0;
}

上一题