正文
增加 8 行删除 8 行
23 行未改动24252627282930313233343536373839404142436 行未改动23 行未改动#include <bits/stdc++.h>#define i first#define hc secondusing namespace std;typedef pair<int ,string> node;//定义键的类型bool operator<(node x,node other){//重载运算符return x.i<other.i||(x.i==other.i&&x.hc<other.hc);//这里只是乱排了个序,对查询无任何影响qwq}map<node,int> dp;//定义记忆化容器int n;string s;int dfs(int i,string hc){if(i==n) return 0;//搜索出口if(dp.find(node(i,hc))!=dp.end()) return dp[node(i,hc)];//dp.find(x)为查询dp与x对应的键的位置,若没有,则返回dp的尾指针,即dp.end()int Min=dfs(i+1,hc+s[i])+1;//字符串+字符(串)是将后面的字符(串)拼接在前面的字符串后面if(hc.length()) Min=min(Min,dfs(i,"")+1);// ""为空字符串if(hc.length()&&hc==s.substr(i,hc.length())) Min=min(Min,dfs(i+hc.length(),hc+hc)+1);return dp[node(i,hc)]=Min;}int main() {6 行未改动23 行未改动24252627282930313233343536373839404142436 行未改动23 行未改动#include <bits/stdc++.h>#define i first#define hc secondusing namespace std;typedef pair<int ,string> node;//定义键的类型bool operator<(node x,node other){//重载运算符return x.i<other.i||(x.i==other.i&&x.hc<other.hc);//这里只是乱排了个序,对查询无任何影响qwq}map<node,int> dp;//定义记忆化容器int n;string s;int dfs(int i,string hc){if(i==n) return 0;//搜索出口if(dp.find(node(i,hc))!=dp.end()) return dp[node(i,hc)];//dp.find(x)为查询dp与x对应的键的位置,若没有,则返回dp的尾指针,即dp.end()int Min=dfs(i+1,hc+s[i])+1;//字符串+字符(串)是将后面的字符(串)拼接在前面的字符串后面if(hc.length()) Min=min(Min,dfs(i,"")+1);// ""为空字符串if(hc.length()&&hc==s.substr(i,hc.length())) Min=min(Min,dfs(i+hc.length(),hc+hc)+1);return dp[node(i,hc)]=Min;}int main() {6 行未改动