当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2890:Matrix Multiplication

题目描述

Many studies have been done on developing efficient algorithms to calculate matrix multiplication. But it remains as a hard topic today. In this problem you are to calculate the 2006th power of a square Boolean matrix where addition and multiplication are defined as follows:

ABA + B
000
011
101
111

Truth Table of Addition

ABAB
000
010
100
111

Truth Table of Multiplication

Let A be a square matrix. The zeroth power of A is the identity matrix. The n-th (n > 0) power of A is the product of A and its (n 1)-th power.

输入解释

The input contains multiple test cases. Each test cases consists of some lines:

  • Line 1: Contains two integers K (K < 1000) and M (0 M ≤ 10K), indicating the dimension of the matrix is K × K and K + M elements of the matrix are 1’s.
  • Lines 2 ~ M + 1: Each contains two integers i and j (0 ≤ i, j < K, ij), indicating the element in the (i + 1)-th row and (j + 1)-th column is 1.

All elements on the primary diagonal of the matrix are 1’s.

输出解释

For each test case output one line containing the number of elements that are 1s in the 2006th power of the given matrix.

输入样例
3 4
1 2
2 1
0 1
0 2
输出样例
7

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2890

最后修改于 2020-10-29T06:46:48+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 131072