编程介的小学生 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 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件