Advertisement
a53

Cuvinte10

a53
Dec 26th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cassert>
  4. #define DIM 300005
  5. #define mod 1000000007
  6. using namespace std;
  7. int n, m, k, i, j, sum, sol, x, sumlen, maxim;
  8. char s[DIM];
  9. int ff[DIM], d[DIM], e[DIM];
  10. struct trie{
  11. int t, len;
  12. trie *f[26];
  13. trie(){
  14. t = 0;
  15. len = 0;
  16. for(int i = 0; i < 26; i++){
  17. f[i] = NULL;
  18. }
  19. }
  20. };
  21. trie *r;
  22. void adauga(trie *r, char *s){
  23. if(*s == 0){
  24. r->t = 1;
  25. }
  26. else{
  27. if(r->f[*s - 'a'] == NULL){
  28. r->f[*s - 'a'] = new trie();
  29. r->f[*s - 'a']->len = r->len + 1;
  30. }
  31. adauga(r->f[*s - 'a'], s + 1);
  32. }
  33. }
  34. void dfs(trie *r){
  35. if(r->t == 1){
  36. d[r->len]++;
  37. return;
  38. }
  39. e[r->len]++;
  40. for(int i = 0; i < 26; i++){
  41. if(r->f[i] != NULL){
  42. dfs(r->f[i]);
  43. }
  44. }
  45. }
  46. int main(){
  47. r = new trie();
  48. cin>> n >> m >> k;
  49. for(i = 1; i <= n; i++){
  50. cin>> s;
  51. adauga(r, s);
  52. }
  53. dfs(r);
  54. for(i = 1; i <= m; i++){
  55. cin>> x;
  56. ff[x]++;
  57. }
  58. sum = sol = 1;
  59. for(i = 1; i <= 300000; i++){
  60. sum = sum * 1LL * k % mod;
  61. sum = (sum - d[i] + mod) % mod;
  62. for(j = 1; j <= ff[i]; j++){
  63. sol = sol * 1LL * (sum - e[i] + mod) % mod;
  64. sum = (sum - 1 + mod) % mod;
  65. }
  66. }
  67. cout<< sol <<"\n";
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement