CF76C.Mutation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Scientists of planet Olympia are conducting an experiment in mutation of primitive organisms. Genome of organism from this planet can be represented as a string of the first KK capital English letters. For each pair of types of genes they assigned ai,ja_{i,j} — a risk of disease occurence in the organism provided that genes of these types are adjacent in the genome, where ii — the 1-based index of the first gene and jj — the index of the second gene. The gene 'A' has index 1, 'B' has index 2 and so on. For example, a3,2a_{3,2} stands for the risk of 'CB' fragment. Risk of disease occurence in the organism is equal to the sum of risks for each pair of adjacent genes in the genome.

Scientists have already obtained a base organism. Some new organisms can be obtained by mutation of this organism. Mutation involves removal of all genes of some particular types. Such removal increases the total risk of disease occurence additionally. For each type of genes scientists determined tit_{i} — the increasement of the total risk of disease occurence provided by removal of all genes having type with index ii . For example, t4t_{4} stands for the value of additional total risk increasement in case of removing all the 'D' genes.

Scientists want to find a number of different organisms that can be obtained from the given one which have the total risk of disease occurence not greater than TT . They can use only the process of mutation described above. Two organisms are considered different if strings representing their genomes are different. Genome should contain at least one gene.

输入格式

The first line of the input contains three integer numbers NN ( 1<=N<=2000001<=N<=200000 ) — length of the genome of base organism, KK ( 1<=K<=221<=K<=22 ) — the maximal index of gene type in the genome and TT ( 1<=T<=21091<=T<=2·10^{9} ) — maximal allowable risk of disease occurence. The second line contains the genome of the given organism. It is a string of the first KK capital English letters having length NN .

The third line contains KK numbers t1,t2,...,tKt_{1},t_{2},...,t_{K} , where tit_{i} is additional risk value of disease occurence provided by removing of all genes of the ii -th type.

The following KK lines contain the elements of the given matrix ai,ja_{i,j} . The ii -th line contains KK numbers. The jj -th number of the ii -th line stands for a risk of disease occurence for the pair of genes, first of which corresponds to the ii -th letter and second of which corresponds to the jj -th letter. The given matrix is not necessarily symmetrical.

All the numbers in the input are integer, non-negative and all of them except TT are not greater than 10910^{9} . It is guaranteed that the maximal possible risk of organism that can be obtained from the given organism is strictly smaller than 2312^{31} .

输出格式

Output the number of organisms that can be obtained from the base one and which have the total risk of disease occurence not greater than TT .

输入输出样例

  • 输入#1

    5 3 13
    BACAC
    4 1 2
    1 2 3
    2 3 4
    3 4 10
    

    输出#1

    5
    

说明/提示

Explanation: one can obtain the following organisms (risks are stated in brackets): BACAC (11), ACAC (10), BAA (5), B (6), AA (4).

首页