Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <stdint.h>
- const uint64_t del = 1e9;
- int main()
- {
- int n = 0;
- scanf("%d", &n);
- uint64_t* nums = malloc(n * sizeof(uint64_t));
- for (uint64_t* i = nums; i != nums + n; i++)
- scanf("%llu", i);
- uint64_t** memo = malloc(n * sizeof(uint64_t*));
- for (uint64_t** i = memo; i != memo + n; i++)
- *i = calloc(n, sizeof(uint64_t));
- for (int i = 0; i < n; i++)
- memo[i][i] = 1;
- for (int r = 1; r < n; r++)
- {
- for (int i = 0, q = r; q < n; i++, q++)
- {
- memo[i][q] = (memo[i + 1][q] % del + memo[i][q - 1] % del - memo[i + 1][q - 1] % del) % del;
- if (nums[i] == nums[q])
- memo[i][q] = (memo[i][q] % del + memo[i + 1][q - 1] % del + 1) % del;
- }
- }
- printf("%llu", memo[0][n - 1] % del);
- for (uint64_t** i = memo; i != memo + n; i++) free(*i);
- free(memo); free(nums);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement