- 魔族密码
- 2016-03-23 11:37:42 @
// input code here
``` #include <iostream>
#include<cstring>
using namespace std;
int max(int a, int b)
{
if (a >= b)
return a;
else
return b;
}
int pd(char a[], char b[])
{
int lena = strlen(a), lenb = strlen(b), num = 1;
if (lena >= lenb)
{
for (int i = 0; i < lenb; i++)
{
if (a[i] != b[i])
{
num = 0; break;
}
}
}
else
{
for (int i = 0; i < lena; i++)
{
if (a[i] != b[i])
{
num = 0; break;
}
}
}
if (num == 1)
return 2;
else
return 1;
}
int main()
{
int n, dp[2005], maxn, max1 = -1;
char ch[2005][75];
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> ch[i];
}
dp[1] = 1;
for (int i = 2; i <= n; i++)
{
maxn = -1;
for (int j = 1; j < i; j++)
{
if (pd(ch[j], ch[i]) == 2)
{
maxn = max(maxn, dp[j]);
}
}dp[i] = maxn + 1;
}
for (int i = 1; i <= n; i++)
{
max1 = max(max1, dp[i]);
}
cout << max1<< endl;
return 0;
}
0 条评论
目前还没有评论...