NC219648. RunningRoutes
描述
输入描述
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; }