编程介的小学生 2017-01-17 15:34 采纳率: 20.5%
浏览 921
已采纳

How Many Free Dimensions?

Description

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 i1i2…ik (1 ≤ ij ≤ n for all j s.t. 1 ≤ j ≤ k). We can then apply a rule of constraint of the form s1s2…sk=t1t2…tk to the subscripts. Here s1s2…sk and t1t2…tk 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 p1p2…pk=q1q2…qk, let α be p1p2…pk and β be q1q2…qk, 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.

Input

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.

Output

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

Sample Input

2 2
ij=ji

3 3
iij=jii

0 0
Sample Output

3
21

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-01-24 15:49
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题