给一个无向图,如果第i个点连接第j条边,那么mat[i][j]=1,否则mat[i][j]=0。

求mat的转置乘以本身得到的矩阵每个位置的和是多少?

理解矩阵的意义就比较好做了。

mat[i][j]表示i点可以连接到j边,转置后相乘的意义是第i边和第j边有公共点。

这样,我们只需要统计每个点的度数,这样我们就知道有多少组这样有公共点的边了,也就是最终的答案了。

如果是mat乘以mat的转置,思考的方法也是一样的。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 100100
typedef long long ll;
using namespace std; int d[maxn],n,m,U,V;
ll ans; int main()
{
scanf("%d%d",&n,&m);
ans=m+m;
while (m--){
scanf("%d%d",&U,&V);
d[U]++,d[V]++;
}
for (int i=; i<=n; i++)
ans+=ll(d[i])*(d[i]-);
cout<<ans<<endl;
return ;
}

SGU196_Matrix Multiplication的更多相关文章

  1. POJ2505 A multiplication game[博弈论]

    A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6028   Accepted:  ...

  2. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  3. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  4. 矩阵乘法 --- hdu 4920 : Matrix multiplication

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  5. Booth Multiplication Algorithm [ASM-MIPS]

    A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...

  6. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  7. hdu4920 Matrix multiplication 模3矩阵乘法

    hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  8. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  9. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...

随机推荐

  1. 框架--NoHttp和OkHttp哪个好用,Volley和NoHttp哪个好用?

    NoHttp和OkHttp哪个好用,Volley和NoHttp哪个好用? NoHttp 源码及Demo托管在Github欢迎大家Star: https://github.com/Y0LANDA/NoH ...

  2. 【Python与机器学习】:利用Keras进行多类分类

    多类分类问题本质上可以分解为多个二分类问题,而解决二分类问题的方法有很多.这里我们利用Keras机器学习框架中的ANN(artificial neural network)来解决多分类问题.这里我们采 ...

  3. mac下配置openfire

    下载 在浏览器中打开如下网址http://www.igniterealtime.org/downloads/index.jsp,根据你的操作系统选择对应的版本进行下载,这里我是在mac下配置的,所以选 ...

  4. php disk_free_space与disk_total_space实例介绍

    php disk_free_space 函数与disk_total_space 函数教程,第一个函数是指函数返回的空间,以字节为单位,在指定的目录,而disk_total_space 函数返回的总空间 ...

  5. EventBus的一个bug??

    今天遇到了一个很奇怪的问题,activity A打开B,A和B中都注册了eventbus,都会接一个list的参数,当然两个list的参数不同,居然会报一个异常,A中List的参数会变成B的类型,错误 ...

  6. Delphi调用REST

    Delphi调用REST很简单,首先在界面上放上: RESTClient1: TRESTClient; RESTRequest1: TRESTRequest; RESTResponse1: TREST ...

  7. 分享一个TP5实现Create()方法的心得

    在TP5中发现用不了以前3.X的Create()方法,虽然用input更严谨,但是字段比较多的话还是有些不艺术的3.X中的实现方法如下: $Model = D('User'); $Model-> ...

  8. ntc 热敏电阻

    来自维基百科  http://zh.wikipedia.org/zh/%E7%83%AD%E6%95%8F%E7%94%B5%E9%98%BB 热敏电阻的电阻值是根据温度由公式计算而来的,知道这一点就 ...

  9. LZW压缩算法

    转载自http://www.cnblogs.com/jillzhang/archive/2006/11/06/551298.html 记录此处仅自己供学习之用 lzw解压缩算法: 用单个字符初始化字符 ...

  10. ORACLE rowid,file# 和 rfile#

    rowid简介 rowid就是唯一标志记录物理位置的一个id,在oracle 8版本以前,rowid由file#+block#+row#组成,占用6个bytes的空间,10 bit 的 file# , ...