2350: A Emphasized Character
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 3s | 8192K | 206 | 73 | Standard |
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;
}