关注
#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,减小空间复杂度
查看原帖
点赞 评论
相关推荐
05-19 19:57
蚌埠学院 Python 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你觉得实习能学到东西吗 #
31367次浏览 639人参与
# 机械人集合!你是什么工程师? #
15415次浏览 89人参与
# 现代汽车前瞻技术研发急速编程挑战赛 #
26160次浏览 212人参与
# 秋招什么时候开投比较合适? #
19377次浏览 276人参与
# 发工资后,你做的第一件事是什么 #
67627次浏览 229人参与
# 如何准备秋招 #
18352次浏览 350人参与
# 百度工作体验 #
219679次浏览 1959人参与
# 机械人与华为的爱恨情仇 #
116293次浏览 942人参与
# 工作中哪个瞬间让你想离职 #
25511次浏览 177人参与
# 硬件应届生薪资是否普遍偏低? #
73660次浏览 514人参与
# 不考虑转正,实习多久合适 #
31658次浏览 145人参与
# 影石Insta360求职进展汇总 #
123188次浏览 1069人参与
# 通信和硬件还有转码的必要吗 #
57315次浏览 526人参与
# 24届的你们都什么时候入职? #
60008次浏览 424人参与
# 面试被问期望薪资时该如何回答 #
256049次浏览 1479人参与
# 实习,不懂就问 #
42382次浏览 648人参与
# 你们公司几号发工资 #
20575次浏览 139人参与
# 软开人,秋招你打算投哪些公司呢 #
102503次浏览 958人参与
# 每个月的工资都是怎么分配的? #
25463次浏览 410人参与
# 如果你有一天可以担任公司的CEO,你会做哪三件事? #
29046次浏览 460人参与
# 你觉得现在还能进互联网吗? #
7640次浏览 130人参与