编程介的小学生 2017-10-31 03:44 采纳率: 20.5%
浏览 591
已采纳

Yong Zheng's Death

Problem Description
Some Chinese emperors ended up with a mysterious death. Many historians like to do researches about this. For example, the 5th Qing dynasty emperor Yong Zheng's death is often argued among historians. Someone say that he was killed by the top assassin Lu Siniang whose family were almost wiped out by Yong Zheng. Someone say that Yong Zheng was poisoned to death because he liked to eat all kinds of Chinese medicines which were said to have the functions of prolonging human lives. Recently, a new document was discovered in Gu Gong(the Forbidden City). It is a secret document written by Yong Zheng's most trusted eunuch. It reads on the cover: "This document tells how Yong Zheng died. But I can't write this in plain text. Whether people will understand this is depend on Gods." Historians finally found out that there are totally n strings in the document making a set S = { s1,s2,... sn}. You can make some death ciphers from the set. A string is called a DEATH CIPHER if and only if it can be divide into two substrings u and v, and u and v are both a prefix of a string from S (Note that u and v can't be empty strings, and u and v can be prefixes of a same string or two different strings).

When all DEATH CIPHERs are put together, a readable article revealing Yong Zheng's death will appear.

Please help historians to figure out the number of different death ciphers.

Input
The input consists of no more than 20 test cases.

For each case, the first line contains an integer n(1 <= n <= 10000), indicating the number of strings in S.

The following n lines contain n strings, indicating the strings in S. Every string only consists of lower case letters and its length is between 1 and 30(inclusive).

The input ends by n = 0.

Output
For each test case, print a number denoting the number of death ciphers.

Sample Input
2
ab
ac
0

Sample Output
9

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-23 15:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条