int main(int argc, char *argv[]) { FILE *fp; int l, r; fp = fopen(*++argv, "r"); while (fscanf(fp, "%d %d", &l, &r) != EOF) { int i, n = 0; for (i = l; i <= r; i++) { int j, prev = -1; for (j = i; j <= r; j++) { int k, p; if (prev > -1) { p = prev; if (pali(j)) p++; } else { p = 0; for (k = i; k <= j; k++) { if (pali(k)) p++; } } if (p % 2 == 0) n++; prev = p; } } printf("%d\n", n); } return 0; }
vector<vector<string>> partition(string s) { int n = s.size(); vector<vector<bool> > pali(s.size(), vector<bool> (s.size() + 1, false)); for (int i = 0; i < n; ++i) { pali[i][i] = pali[i][i + 1] = true; } for (int len = 2; len <= n; ++len) { for (int i = 0; i + len <= n; ++i) { int j = i + len; if (s[i] == s[j - 1] && pali[i + 1][j - 1]) { pali[i][j] = true; } } } vector<vector<string> > ans; vector<string> now; _gen(s, 0, pali, ans, now); return ans; }