关注
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long;
using namespace std;
bool comp(const string &s1,const string &s2)
{
return s1.length()<s2.length();
}
vectornewStr;
void mincut(const string& str, const set& dict,int s,string sstr)
{
if(s==str.length())
{
newStr.push_back(sstr);
}
for(auto it=dict.begin();it!=dict.end();it++)
{
string t=*it;
int i;
for(i=0;i<t.length();++i)
if(t[i]!=str[i+s])break;
if(i==t.length()&&s+i<=str.length())
{
if(s) t=" "+t;
mincut(str,dict,s+i,sstr+t);
}
}
}
int main(int argc, const char * argv[])
{
string strS;
string dictStr;
int nDict;
set dict;
cin>>strS;
cin>>nDict;
for (int i = 0; i < nDict; i++)
{
cin>>dictStr;
dict.insert(dictStr);
}
mincut(strS, dict,0,string());
if(newStr.size())
{
sort(newStr.begin(),newStr.end(),comp);
cout<<newStr[0];
}
else
{
cout<<"n/a";
}
return 0;
}
因为没有看到最后如果不匹配就输出"n/a",所以提交的代码里没有最后的条件判断,通过率75%,可以用一个string代替vector,减小空间复杂度
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
转发
昨天 17:06
北京理工大学 计算机类 点赞 评论 收藏
转发
投递蔚来等公司10个岗位 >
点赞 评论 收藏
转发
牛客热帖
正在热议
# 和牛牛一起刷题打卡 #
4428次浏览 420人参与
# 机械制造薪资爆料 #
340763次浏览 4042人参与
# 牛客帮帮团来啦!有问必答 #
981708次浏览 15223人参与
# 通信硬件薪资爆料 #
241859次浏览 2281人参与
# 腾讯工作体验 #
146294次浏览 1405人参与
# 如何写一份好简历 #
300577次浏览 4324人参与
# 实习必须要去大厂吗? #
17993次浏览 263人参与
# 你的简历改到第几版了 #
323101次浏览 4854人参与
# 晒一晒我的offer #
3649808次浏览 56913人参与
# 2022毕业生求职现身说法 #
20368次浏览 310人参与
# 产品人专业大盘点 #
15073次浏览 120人参与
# 毕业租房也有小确幸 #
31786次浏览 1806人参与
# 浅聊一下我实习的辛苦费 #
93263次浏览 916人参与
# 视觉/交互/设计岗位评价 #
3356次浏览 59人参与
# 为什么国企只招应届生 #
55999次浏览 407人参与
# 你觉得机械有必要实习吗 #
10073次浏览 130人参与
# 为什么那么多公司毁约 #
54671次浏览 482人参与
# 在国企工作的人,躺平了吗? #
105370次浏览 1335人参与
# 来选选带哪个offer回家过年 #
185188次浏览 1771人参与
# 找工作时遇到的神仙HR #
195701次浏览 1837人参与