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

建议使用的浏览器:

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

2829:How Many Free Dimensions?

题目描述

In calculating the outer product of vectors, existence of constraints usually makes it that not all the components of the product are independent of the others. For example, the outer product of two two-dimensional vectors A = (a1, a2) and B = (b1, b2), C = A × B = (c11, c12, c21, c22). If we set c12 = c21, then only three of the four components of C is independent, or C has three free dimensions.

Now we have k n-dimensional vectors A1, A2, …, Ak. The product of them is a vector of nk components Z = (zα) where α enumerates all possible subscripts i1i2ik (1 ≤ ijn for all j s.t. 1 ≤ jk). We can then apply a rule of constraint of the form s1s2sk=t1t2tk to the subscripts. Here s1s2sk and t1t2tk are two strings consisting of the same set of lowercase letters. A letter appearing in one string will also appear in the other one and it can have multiple occurrences in a string. When a rule is applied, the letters in it are replaced by arbitrary integers between 1 and n (inclusive) provided that the same letters are replaced by the same integers and different letters are replaced by different integers. If a resulted string after replacements is p1p2pk=q1q2qk, let α be p1p2pk and β be q1q2qk, then we set zα = zβ. Given the number of vectors and their dimensions and a rule of constraint, you are required to compute the number of free dimensions of the product of the vectors.

输入解释

The input contains several test cases. Each test case consists of two lines followed by a blank one. On the first line there are two integers which are n and k in the order they appear. On the second line is a rule of constraint. Two zeroes on a separate line follow the last test case.

输出解释

For each test case, output one line containing the number of free dimensions of the product of vectors.

输入样例
2 2
ij=ji

3 3
iij=jii

0 0
输出样例
3
21
提示

In the second test case in the sample input, the rule iij=jii represents the constraints z112 = z211, z113 = z311, z221 = z122, z223 = z322, z331 = z133 and z332 = z233.

You can safely assume that all calculations can be done with 64-bit integers.


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

源链接: POJ-2829

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

共提交 0

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