时间限制:3000 ms  |  内存限制:65535 KB
难度:4
描述
所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba"。当然,我们给你的问题不会再简单到判断一个字符串是不是回文字符串。现在要求你,给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符串。
输入
第一行给出整数N(0<N<100)

接下来的N行,每行一个字符串,每个字符串长度不超过1000.
输出
每行输出所需添加的最少字符数
样例输入
1
Ab3bd
样例输出
2
来源
IOI 2000
上传者
hzyqazasdf
 #include <iostream>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string>
 #include <string.h>
 #include <algorithm>//reverse
 #include <vector>
 using namespace std;
 #define debug(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
 ][];

 int dphwzfc(char *bufings, int n);
 int main(){
     int N;
     scanf("%d", &N);
     getchar();
     while (N--) {
         ] = {};
         ] = {};
         ;
         scanf("%s", buf);
         getchar();
         memset(dpth, 0x00, sizeof(dpth));
         int buflen = strlen(buf);
          || buflen == ){
             printf("%d\n", result);
             continue;
         }
         //int lcslen = 0;
         ;
         ;
         ) {
             s[sidx++] = buf[idx--];
         }
         //cout << sidx << endl;
         s[sidx] = '\0';
 //        for (int i = 0; i < buflen; ++i) {
 //            if(s[0] == buf[i]){
 //                dpth[0][i] = 1;
 //            }else {
 //                dpth[0][i] = 0;
 //            }
 //            if(s[i] == buf[0]){
 //                dpth[i][0] = 1;
 //            }else {
 //                dpth[i][0] = 0;
 //            }
 //        }

         ; i < buflen; ++i) {
             ; j < buflen; ++j) {
                 if(s[i] == buf[j]){
                     dpth[i+][j+] = dpth[i][j]+;
                 }else{
                     dpth[i+][j+] = max(dpth[i+][j], dpth[i][j+]);
                 }

 //                if(dpth[i][j] > lcslen){
 //                    lcslen = dpth[i][j];
 //                }

             }
         }
 //cout << dpth[buflen-1][buflen-1] << endl;
         result = buflen - dpth[buflen][buflen];
         printf("%d\n", result);
     }
     ;
 }

滚动数组

滚动数组的作用在于优化空间,主要应用在递推或动态规划中(如01背包问题)。

滚动数组实际是一种节省空间的办法,时间上没啥优势,多用于DP中

最新文章

  1. salesforce 零基础学习(五十二)Trigger使用篇(二)
  2. Lucene.net应用
  3. Win8下Visual Studio编译报“无法注册程序集***dll- 拒绝访问。请确保您正在以管理员身份运行应用程序。对注册表项”***“的访问被拒绝。”问题修正(转)
  4. js常用函数陆续总结
  5. Sed替换行和字符shell
  6. java 用socket制作一个简易多人聊天室
  7. KMP算法的理解
  8. 小白日记41:kali渗透测试之Web渗透-SQL手工注入(三)-猜测列名、表名、库名、字段内容,数据库写入
  9. 关于Azure存储账户中存储虚拟机VHD文件的注意事项
  10. FZU1686 神龙的难题 dancing links 重复覆盖
  11. 5、范围标签&lt;fieldset&gt;&lt;/fieldset&gt;
  12. 004-Python字符串
  13. 将图片保存成png 或者jpg格式
  14. ASP.NET Core的身份认证框架IdentityServer4(8)- 使用密码认证方式控制API访问
  15. 还原NuGet程序包
  16. scrapy 爬虫基础
  17. 使用一个Python脚本来运行一个简单的Django项目
  18. django之Models和ORM
  19. WebForm 【Repeater】展示数据
  20. .NETCore_初探

热门文章

  1. IDEA之google style配置(IDEA)
  2. leetcode 86. Partition List
  3. [BZOJ2656][codevs1207][Zjoi2012]数列(sequence)
  4. Sqli-LABS通关笔录-11[sql注入之万能密码以及登录框报错注入]
  5. OpenCV成长之路(10):视频的处理
  6. git 教程(12)--分支管理
  7. 把ZenCart在线商店搭建到本地
  8. MyBatis 中 Result Maps collection already contains value for xxx 错误原因
  9. 11.2---字符串数组排序,删除变位词(CC150)
  10. Java Dao设计模式