社区讨论
51分求助,#1#2#3WA
P1019[NOIP 2000 提高组] 单词接龙(疑似错题)参与者 4已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lodj3zey
- 此快照首次捕获于
- 2023/10/31 07:26 2 年前
- 此快照最后确认于
- 2023/11/06 22:42 2 年前
CPP
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string A[20];
int cnt[20];
int ans, n;
void DFS(const string & a, int prev)
{
int len = a.size(), total = prev + len;
ans = max(ans, total);
for (int i = 1; i <= len; i++)
{
for (int j = 0; j < n; j++)
{
if (cnt[j] < 2 && A[j].size() > i && a.compare(len - i, i, A[j], 0, i) == 0)
{
cnt[j]++;
DFS(A[j], total - i);
cnt[j]--;
}
}
}
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> A[i];
char start;
cin >> start;
for (int i = 0; i < n; i++)
{
if (A[i][0] == start)
DFS(A[i], 0);
}
cout << ans;
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...