宁波怎么做外贸公司网站,夏天做啥网站致富,中国星子网,网站建设急单1. 计算0~9为结尾的最长子串长度
2. 对于每个数字#xff0c;比较其开头可连接子串长度1
与 原来以其末位为末尾的子串长度
3. 更新以其末位为末尾的子串长度
#includeiostream
#includestring.husing namespace std;// 相当于记录… 1. 计算0~9为结尾的最长子串长度
2. 对于每个数字比较其开头可连接子串长度1
与 原来以其末位为末尾的子串长度
3. 更新以其末位为末尾的子串长度
#includeiostream
#includestring.husing namespace std;// 相当于记录0~9为末尾的最长子串长度
int dp[10] { 0 };
int main()
{int num; cin num;for(int i0;inum;i){char temp[10] { 0 };scanf(%s, temp);// 记录数字首尾数字int e temp[strlen(temp) - 1] - 0;int f temp[0] - 0;// 当前数字能连接某一子串的情况// 和 不连接// 两种情况找最大值并更新数值 dp[e] max(dp[f] 1, dp[e]);}int max -1;for (int i 0; i 9; i){if (max dp[i])max dp[i];}cout num-max;return 0;
}