#include<bits/stdc++.h>
using namespace std;
int dp[10],n,res;
int main(){
cin>>n;
for(int i=0;i<n;i++) {
string s;
cin>>s;
int a=s[0]-'0',b=s.back()-'0';
dp[b]=max(dp[b],dp[a]+1);
res=max(res,dp[b]);
}
cout<<n-res<<endl;
return 0;
}
接龙数列 蓝桥杯 线性dp
最新推荐文章于 2024-09-04 18:55:10 发布