2350: A Emphasized Character

2350: A Emphasized Character


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K20673Standard

In Tom's telephone book, persons is order by their essentiality but not their dictionary order. He is annoyed that he can't find one item quickly. One day, he decide to emphasize a typical character in each item. Each typical character in after word must be greater or equal to the previous typical character. Given the list of person name, he want to know how many ways he can emphasize.

Input

There are multi-case in input file. The first line of one case is the integer n (n<=20) of word list. There are exact one word (length is less than 16) in the next n lines, the word is make up of only lower letter (from 'a' to 'z'). The end of input is identified by n=0.

Output

For each test case, output the total number of different ways in one line. Notice if there are two same letter in different place of one word, it will be counted by two ways.

Sample Input

2
hello
jlu
0

Sample Output

11

 

Problem Source: 5th JLU Programming Contest - Personal, skywind

#include<stdio.h>
#include<string.h>
int main()
{
 int ans[30][30];
 char a[30][30];
 int n,i,j,k;
 while(scanf("%d",&n),n)
 {
  for(i=1;i<=n;i++)
  {
   scanf("%s",a[i]);
  }
  memset(ans,0,sizeof(ans));
  int len_1=strlen(a[1]);
  for(i=0;i<len_1;i++)
   ans[1][i]=1;
  for(i=2;i<=n;i++)
  {
   int len=strlen(a[i]);
   for(j=0;j<len;j++)
   {
    int temp=0;
    int len_pre=strlen(a[i-1]);
    for(k=0;k<len_pre;k++)
    {
     if(a[i][j]>=a[i-1][k]) temp+=ans[i-1][k];
    }
    ans[i][j]=temp;
   }
  }
  int sum=0;
  int len_last=strlen(a[n]);
  for(i=0;i<len_last;i++)
   sum+=ans[n][i];
  printf("%d/n",sum);
 }
 return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值