Vijos P1028 - 魔族密码
传送门
思路
一道非常水的DP。
代码
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = 2000 + 10;
const int INF = 0x3f3f3f3f;
char str[MAXN][80];
int dp[MAXN];
int main()
{
//freopen("input.txt", "r", stdin);
int n, i, j, vmax = -1;
scanf("%d", &n);
char *pc;
for (i = 0; i < n; i++)
scanf("%s", str[i]);
for (i = 0; i < n; i++)
for (j = 0; j < i; j++)
if ((pc = strstr(str[i], str[j])) != NULL && pc == str[i])
{
dp[i] = max(dp[i], dp[j] + 1);
vmax = max(dp[i], vmax);
}
printf("%d\n", vmax + 1);
return 0;
}