一身转战三千里,一键曾当百万师

你还记得你吃过多少面包吗?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include<algorithm>
using namespace std;
typedef struct
{
int fro;
int beh;
}pai;
int main()
{
int n;
cin >> n;
int c = 1;
pai* lin = new pai[n + 10];
int* dp = new int[n + 10];
for (int i = 1; i <= n; i++)
{
int t;
cin >> t;
lin[i].beh = t % 10;
while (t > 9)
{
t /= 10;
}
lin[i].fro = t;
}
for (int i = 1; i <= n; i++)
{
dp[i] = 1;
for (int j = 1; j < i; j++)
{
if (lin[i].fro == lin[j].beh)
{
dp[i] = max(dp[i],dp[j] + 1);
}
}
c = max(c, dp[i]);
}
cout << n - c << endl;
delete[] lin;
delete[] dp;
return 0;
}

以上皆为测试用的错误示范