DP:about string

Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s =”aab”,
Return
[
[“aa”,”b”],
[“a”,”a”,”b”]
]

用递归的思想求解,DP表示不会。。。。。。
相关问题:

void dfs(string s, vector<string> &path, vector<vector<string>> &result)
{
    if(s.size() < 1)
    {
        result.push_back(path);
        return ;
    }

    for(int i = 0; i < s.size(); ++i)
    {
        int start = 0;
        int end = i;

        while(start < end)
        {
            if(s[start] == s[end])
            {
                ++start;
                --end;
            }
            else break;
        }

        if(start >= end)
        {
            path.push_back(s.substr(0, i+1));
            dfs(s.substr(i+1), path, result);
            path.pop_back();
        }
    }
}

vector<vector<string>> partition(string s) 
{
    vector<vector<string>> result;
    vector<string> path;
    dfs(s, path, result);

    return result;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
给下列程序添加注释:void DWAPlannerROS::initialize( std::string name, tf2_ros::Buffer* tf, costmap_2d::Costmap2DROS* costmap_ros) { if (! isInitialized()) { ros::NodeHandle private_nh("~/" + name); g_plan_pub_ = private_nh.advertise<nav_msgs::Path>("global_plan", 1); l_plan_pub_ = private_nh.advertise<nav_msgs::Path>("local_plan", 1); tf_ = tf; costmap_ros_ = costmap_ros; costmap_ros_->getRobotPose(current_pose_); // make sure to update the costmap we'll use for this cycle costmap_2d::Costmap2D* costmap = costmap_ros_->getCostmap(); planner_util_.initialize(tf, costmap, costmap_ros_->getGlobalFrameID()); //create the actual planner that we'll use.. it'll configure itself from the parameter server dp_ = boost::shared_ptr<DWAPlanner>(new DWAPlanner(name, &planner_util_)); if( private_nh.getParam( "odom_topic", odom_topic_ )) { odom_helper_.setOdomTopic( odom_topic_ ); } initialized_ = true; // Warn about deprecated parameters -- remove this block in N-turtle nav_core::warnRenamedParameter(private_nh, "max_vel_trans", "max_trans_vel"); nav_core::warnRenamedParameter(private_nh, "min_vel_trans", "min_trans_vel"); nav_core::warnRenamedParameter(private_nh, "max_vel_theta", "max_rot_vel"); nav_core::warnRenamedParameter(private_nh, "min_vel_theta", "min_rot_vel"); nav_core::warnRenamedParameter(private_nh, "acc_lim_trans", "acc_limit_trans"); nav_core::warnRenamedParameter(private_nh, "theta_stopped_vel", "rot_stopped_vel"); dsrv_ = new dynamic_reconfigure::Server<DWAPlannerConfig>(private_nh); dynamic_reconfigure::Server<DWAPlannerConfig>::CallbackType cb = boost::bind(&DWAPlannerROS::reconfigureCB, this, _1, 2); dsrv->setCallback(cb); } else{ ROS_WARN("This planner has already been initialized, doing nothing."); } }
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值