编程介的小学生 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 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计