SGU196_Matrix Multiplication
给一个无向图,如果第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的更多相关文章
- POJ2505 A multiplication game[博弈论]
A multiplication game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6028 Accepted: ...
- 【数学】Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total S ...
- hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- 矩阵乘法 --- hdu 4920 : Matrix multiplication
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Booth Multiplication Algorithm [ASM-MIPS]
A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...
- hdu4951 Multiplication table (乘法表的奥秘)
http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence
题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...
随机推荐
- 使用ADD_CUSTOM_COMMAND 添加自定义命令
e.g. ADD_CUSTOM_COMMAND( TARGET world_server COMMAND cp ${CMAKE_SOURCE_DIR}/CMak ...
- l类型转换错误ClassCastException
出现问题原因story中参数写错:
- Intel汇编语言程序设计学习笔记1
第一章 汇编器链接器:汇编器将汇编语言翻译成机器语言,链接器将单个文件合并为可执行文件 intel 80X86系列处理器的汇编语言与VAX或者motorala 68x00等系统的汇编是否相同?不相同, ...
- Navicat链接Oracle提示ORA-12737
ORA-12737: Instant Client Light: unsupported server character set string Cause: The character set sp ...
- LR11-更改licence
准备工作: 超级licence 6.5w:AEACFSJI-YJKJKJJKEJIJD-BCLBR AEACFSJI-YJKJKJJKEJIJD-BCLBR 操作步骤: 1.网上下载lr删除注册表工具 ...
- EXT学习之——获取下拉框combobox的值与显示名
//申请科室 var comboboxdept = new Ext.form.ComboBox({ xtype: "combobox", name: "Gender&qu ...
- 北京市小升初 zz
发信人: django (牛魔王), 信区: SchoolEstate 标 题: 北京市小升初掐尖方式的演变过程(看后恍然大悟) 发信站: 水木社区 (Thu Feb 4 10:51:23 201 ...
- NHibernate系列文章十二:Load/Get方法
摘要 NHibernate提供两个方法按主键值查找对象:Load/Get. 1. Load/Get方法的区别 Load: Load方法可以对查询进行优化. Load方法实际得到一proxy对象,并不立 ...
- js动态生成input指定My97DatePicker时间问题
js生成的input指定onclick时间: 以下1.2为错误: onclick="WdatePicker()"; onclick=WdatePicker(); 若指定到windo ...
- ASP.NET中调用存储过程方法
两种不同的存储过程调用方法 为了突出新方法的优点,首先介绍一下在.NET中调用存储过程的“官方”方法.另外,本文的所有示例程序均工作于SqlServer数据库上,其它情况类似,以后不再一一说明.本文所 ...