In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network:
People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.
Different roads may have had different lengths, but all the lengths were positive integers.
Snuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom.
Determine whether there exists a road network such that for each u and v, the integer Au,v at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v. If such a network exist, find the shortest possible total length of the roads.
Constraints
1≤N≤300
If i≠j, 1≤Ai,j=Aj,i≤109.
Ai,i=0
输入
Input is given from Standard Input in the following format:
N
A1,1 A1,2 … A1,N
A2,1 A2,2 … A2,N
…
AN,1 AN,2 … AN,N
输出
If there exists no network that satisfies the condition, print -1. If it exists, print the shortest possible total length of the roads.
样例输入
3 0 1 3 1 0 2 3 2 0
样例输出
3
题意:这是一个凸包问题,将N个点分成几个不同的n个点,每个都能构成一个凸包,暴力解决,将在一条直线上的点都删除,剩余的将构成凸包
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 205
using namespace std;
typedef long long ll;
const ll mod=998244353;
int main()
{
int x[505],y[505];
int vis[505];
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%d%d",&x[i],&y[i]);
}
vis[0]=1;
for(int i=1;i<=n;i++)
{
vis[i]=(vis[i-1]*2)%mod;
}
ll sum=vis[n]-1-n-n*(n-1)/2;
int countt=0;
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++) {
int countt = 0;
for (int k = j+1; k < n; k++) {
if ((x[j]-x[i]) * (y[k]-y[j]) == (x[k]-x[j]) * (y[j]-y[i]))
countt++;
}
sum=(sum-(maze[countt]-1)+mod)%mod;
}
}
printf("%lld\n", sum);
}
return 0;
}