。dp回文子串 通常在dp数组中存放的是 从i到j是否是回文子串

1.动态规划

2.中心扩展法

 #include<iostream>
 #include<algorithm>
 #include<string>
 using namespace std;
 ][] = {  };
 int main(void)
 {
     string s1;
     while (cin >> s1)
     {
         int length = s1.length();
         int i;
         ; i <= length - ; ++i)
             dp[i][i] = ;
         int j;
         ; i >=; --i)
         {
             ; j <=length-; ++j)
             {
                 if (s1[i] == s1[j])
                 {
                     dp[i][j] = dp[i + ][j - ] + ;
                 }
                 else
                 {
                     dp[i][j] = max(dp[i + ][j], dp[i][j - ]);
                 }
             }
         }
         cout << ][length - ] << endl;
     }
     ;
 }
 #include<iostream>
 #include<algorithm>
 #include<string>
 using namespace std;
 ][] = {  };
 int main(void)
 {
     string s1;
     while (cin >> s1)
     {
         int length = s1.length();
         int i;
         ; i <= length - ; ++i)
             dp[i][i] = ;
         int j;
         ; i >= ; --i)
         {
             ; j <= length - ; ++j)
             {
                 if (s1[i] != s1[j])
                 {
                     dp[i][j] = dp[i + ][j] + dp[i][j - ] - dp[i + ][j - ];
                 }
                 else
                 {
                     dp[i][j] = dp[i + ][j] + dp[i][j - ] - dp[i + ][j - ] + dp[i + ][j - ] + ;
                 }
             }
         }
         cout << ][length - ] << endl;
     }
     ;
 }
 #include<iostream>
 #include<algorithm>
 #include<string>
 using namespace std;
 ];           //长度
 bool ispalindrome(string s,int start,int end)
 {
     while (start <= end)
     {
         if (s[start] != s[end])
         {
             return false;
         }
         ++start;
         --end;
     }
     return true;
 }
 int main(void)
 {
     string s;
     while (cin >> s)
     {
         int length = s.length();
         int i;
         ; i <= length; ++i)
         {
             dp[i] = i - ;
             , i-) == true)
             {
                 dp[i] = ;
             }
         }
         int j;
         ; i <= length-; ++i)
         {
             ; j <= i; ++j)
             {
                 if (ispalindrome(s, j, i) == true)
                 {
                     dp[i + ] = min(dp[i + ], dp[j] + );
                 }
             }
         }
         cout << "需要分割的次数为" << dp[length] << "次"<<endl;
     }
     ;
 }

dp回文的更多相关文章

  1. poj 1159 dp回文串

    题意:添加最少的字符使之成为回文串 #include<cstdio> #include<iostream> #include<algorithm> #include ...

  2. POJ 3280 Cheapest Palindrome(DP 回文变形)

    题目链接:http://poj.org/problem?id=3280 题目大意:给定一个字符串,可以删除增加,每个操作都有代价,求出将字符串转换成回文串的最小代价 Sample Input 3 4 ...

  3. poj 3280 Cheapest Palindrome ---(DP 回文串)

    题目链接:http://poj.org/problem?id=3280 思路: dp[i][j] :=第i个字符到第j个字符之间形成回文串的最小费用. dp[i][j]=min(dp[i+1][j]+ ...

  4. HDU4745--区间DP+回文串

    这题的题意为,给你一个环状的字符串,有两只兔子分别从某任意的石头上开始跳跃.一只顺时针跳.一只逆时针跳.两只兔子每一次落脚处石头的质量都相同.兔子要一步一步的跳,且不能跳到之前跳到过的地方.总的来说, ...

  5. LightOJ - 1205:Palindromic Numbers (数位DP&回文串)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  6. CodeForces-245H:Queries for Number of Palindromes(3-14:区间DP||回文串)

    Times:5000ms: Memory limit:262144 kB 给定字符串S(|S|<=5000),下标由1开始.然后Q个问题(Q<=1e6),对于每个问题,给定L,R,回答区间 ...

  7. Palindrome Partition CodeForces - 932G 回文树+DP+(回文后缀的等差性质)

    题意: 给出一个长度为偶数的字符串S,要求把S分成k部分,其中k为任意偶数,设为a[1..k],且满足对于任意的i,有a[i]=a[k-i+1].问划分的方案数. n<=1000000 题解: ...

  8. GDUT 校赛02 dp回文串

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABSkAAAIhCAIAAAAtmainAAAgAElEQVR4nOzdfaxkd33n+ZJacstqa3 ...

  9. Lightoj1205——Palindromic Numbers(数位dp+回文数)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

随机推荐

  1. 极光推送经验之谈-Java后台服务器实现极光推送的两种实现方式

    原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/6439313.html Java后台实现极光推送有两种方式,一种是使用极光推送官方提供的推送请 ...

  2. 聊聊数据库~4.SQL优化篇

    1.5.查询的艺术 上期回顾:https://www.cnblogs.com/dotnetcrazy/p/10399838.html 本节脚本:https://github.com/lotapp/Ba ...

  3. DSAPI WIN7风格

    在Winform项目中,有时需要将UI变成适应Vista/Windows7/8/10的风格,通过"选用"以下代码来使你的UI支持系统主题渲染. 注:该功能不支持XP,建议使用DS控 ...

  4. Jquery简单学习

    Jquery是一个JavaScript的函数库,Jquery是一个写得少但做的多的轻量级JavaScript库 Jquery用美元$定义. Jquery的action执行对元素的操作 文档就绪函数: ...

  5. Linux journalctl命令

    在Systemd出现之前,Linux系统及各应用的日志都是分别管理的,Systemd开始统一管理了所有Unit的启动日志,这样带来的好处就是可以只用一个 journalctl命令,查看所有内核和应用的 ...

  6. jQuery里面的DOM操作(查找,创建,添加,删除节点)

    一:创建元素节点(添加) 创建元素节点并且把节点作为元素的子节点添加到DOM树上 append(): 在元素下添加元素 用法:$("id").append("定义的节点& ...

  7. 基于mapnik做切片服务器的几点总结

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 在地图服务器的整体方案中,移动端采用矢量切片,样式解析采用th ...

  8. 从零学习Fluter(八):Flutter的四种运行模式--Debug、Release、Profile和test以及命名规范

    从零学习Fluter(八):Flutter的四种运行模式--Debug.Release.Profile和test以及命名规范 好几天没有跟新我的这个系列文章,一是因为这两天我又在之前的基础上,重新认识 ...

  9. 业务与IT技术

    最近听一个同事又再次提问关于业务比技术重要,是真的吗? 今天我们再来看一下.      一,什么是业务? 业务意指某种有目的的工作或工作项目.技术可以指人类对机器.硬件或人造器皿的运用,但它也可以包含 ...

  10. jqery autocomplete 动态传递参数的问题

    今天弄一个autocomplete 向后后台动态传递参数的问题 老的写法: params: { "saleid": $("#divSalesman input[field ...