题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5232
解题思路:
这是一个简单的图论题,首先Gorwin要和所有人握手,这里贡献答案 2∗n ,然后矩阵中的每一对都会贡献 2 。 所以数一下矩阵里面有几个 1 ,然后再加上 2∗n 就是答案了。复杂度 o(n∗n)
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i,j,ans=2*n,x;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&x);
ans+=x;
}
printf("%d\n",ans);
}
return 0;
}