uva 10029

來源:互聯網
上載者:User


#include <stdio.h>#include <string.h>#define max(a, b) (a) > (b) ? (a) :(b)const int N = 25005;const int M = 20;int n = 0, dp[N], ans = 1;char word[N][M];void add(char *a, char *s, char ch, int in) {int i;for (i = 0; i < in; i++)s[i] = a[i];s[in] = ch;for ( ; a[i]; i++)s[i + 1] = a[i];s[i + 1] = '\0';}void del (char *a, char *s, int in) {int i;for (i = 0; i < in; i++)s[i] = a[i];for (i++; a[i]; i++)s[i - 1] = a[i];s[i - 1] = '\0';}void change(char *a, char *s, char ch, int in) {int i;for (i = 0; a[i]; i++)s[i] = a[i];    s[in] = ch;s[i] = '\0';}void handle(char *now, char *s, char ch, int t, int flag) {if (flag == 0) change(now, s, ch, t);else if (flag == 1) del(now, s, t);else add(now, s, ch, t);}int search(char *s, int r) {r--;int l = 0, mid;while (l <= r) {mid = (l + r) / 2;int flag = strcmp(word[mid], s);if (flag == 0) return mid;else if (flag < 0) l = mid + 1;else r = mid - 1;}return -1;}int main() {char str[M];while (scanf("%s", word[n]) == 1) n++;for (int i = 0; i < n; i++) {dp[i] = 1;for (int k = 0; k < 3; k++) {for (int j = 0; word[i][j]; j++) {for (int t = 0; t < 26; t++) {handle(word[i], str, 'a' + t, j, k);if (strcmp(word[i], str) < 0) break;int f = search(str, i);if (f >= 0)dp[i] = max(dp[i], dp[f] + 1);}}}ans = max(ans, dp[i]);}printf("%d\n", ans);return 0;}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.