CodeForces-159D Palindrome pairs DP
2017-02-22 19:09
302 查看
也可以用Manacher算法做 但是我觉得有点麻烦..而且没搞出来= =
#include <cstdio> #include <string> #include <cstring> #include <queue> #include <algorithm> #include <functional> #include <vector> #include <iomanip> #include <cmath> #include <iostream> #include <sstream> #include <stack> #include <set> #include <bitset> using namespace std; const int MAX = 2005; int F[MAX], G[MAX]; string Str; int main() { while (cin >> Str) { size_t len = Str.length(); memset(F, 0, sizeof(F)); memset(G, 0, sizeof(G)); for (int i = 0; i < len; i++) { for (int l = i, r = i; l >= 0 && r < len && Str[l] == Str[r]; l--, r++) F[l]++, G[r]++; for (int l = i, r = i + 1; l >= 0 && r < len && Str[l] == Str[r]; l--, r++) F[l]++, G[r]++; } for (int i = 1; i < len; i++) G[i] += G[i - 1]; long long Ans = 0; for (int i = 1; i < len; i++) Ans += G[i - 1] * F[i]; cout << Ans << endl; } return 0; }
相关文章推荐
- CodeForces 396C
- Codeforces 602A Two Bases
- Codeforces 633C Spy Syndrome 2(DP + Trie树)
- Codeforces 743C-Vladik and fractions(构造)
- CodeForces 820A Mister B and Book Reading
- Codeforces 416E DP
- Codeforces 459C
- CodeForces 594D REQ(树状数组)
- Codeforces 691E Xor-sequences【矩阵快速幂,好题】
- CodeForces 745A Hongcow Learns the Cyclic Shift
- CodeForces 665C
- CodeForces - 892C Pride GCD
- Codeforces 258B. Little Elephant and Elections【数位DP,DFS】
- CodeForces 316D3 PE Lesson
- codeforces 696C C. PLEASE(概率+快速幂)
- Codeforces 400D. Dima and Bacteria【并查集+最短路】
- CodeForces 821A Okabe and Future Gadget Laboratory
- Codeforces-343D:Water Tree(树链剖分)
- Codeforces 446B DZY Loves Modification
- CodeForces 171F ucyhf 第n个反素数