Advertisement
paranid5

kekc

Nov 2nd, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdint.h>
  4.  
  5. const uint64_t del = 1e9;
  6.  
  7. int main()
  8. {
  9.     int n = 0;
  10.     scanf("%d", &n);
  11.  
  12.     uint64_t* nums = malloc(n * sizeof(uint64_t));
  13.     for (uint64_t* i = nums; i != nums + n; i++)
  14.         scanf("%llu", i);
  15.  
  16.     uint64_t** memo = malloc(n * sizeof(uint64_t*));
  17.     for (uint64_t** i = memo; i != memo + n; i++)
  18.         *i = calloc(n, sizeof(uint64_t));
  19.  
  20.     for (int i = 0; i < n; i++)
  21.         memo[i][i] = 1;
  22.  
  23.     for (int r = 1; r < n; r++)
  24.     {
  25.         for (int i = 0, q = r; q < n; i++, q++)
  26.         {
  27.             memo[i][q] = (memo[i + 1][q] % del + memo[i][q - 1] % del - memo[i + 1][q - 1] % del) % del;
  28.  
  29.             if (nums[i] == nums[q])
  30.                 memo[i][q] = (memo[i][q] % del + memo[i + 1][q - 1] % del + 1) % del;
  31.         }
  32.     }
  33.  
  34.     printf("%llu",  memo[0][n - 1] % del);
  35.  
  36.     for (uint64_t** i = memo; i != memo + n; i++) free(*i);
  37.     free(memo); free(nums);
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement