设为首页 加入收藏

TOP

HDU-4628 Pieces 状压DP
2015-07-20 17:26:55 来源: 作者: 【 】 浏览:3
Tags:HDU-4628 Pieces 状压

给出一行字符串,每次可以删去一个回文子串,子串可以是不连续的,因此用状压比较好模拟,求删掉整个字符串需要的最少步数。

字符串的最大长度为16,因此不能逐行枚举状态,首先预处理出来所有的的回文子串,然后从第一步开始,依次状压第i步能到达的状态,如果能达到母串,跳出。

还有初始化不要用图省事用memset。。不优越的姿势+函数导致T了数发。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           using namespace std; char s[20]; char s1[20]; int ans; int num; int dp[1<<17][17]; int visit[20]; int Pow[15]; int a[1<<17]; bool solve(char str[]) { int flag=1; int start=0; int end=strlen(str)-1; while(start<=end) { if(str[start]!=str[end]) { flag=0; break; } start++; end--; } if(flag) { return true; } else { return false; } } int main() { int t; int sum; Pow[0]=1; for(int i=1;i<=18;i++) { Pow[i]=Pow[i-1]*2; } scanf("%d",&t); while(t--) { num=0; scanf("%s",s); int len=strlen(s); int mos=1<<(len); for(int i=1;i<=len;i++) { for(int j=1;j
          
           

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4405 Aeroplane chess (概率.. 下一篇BZOJ 2734 HNOI2012 集合选数 状..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python爬虫教程(从 (2025-12-26 16:49:14)
·【全269集】B站最详 (2025-12-26 16:49:11)
·Python爬虫详解:原 (2025-12-26 16:49:09)
·Spring Boot Java: (2025-12-26 16:20:19)
·Spring BootでHello (2025-12-26 16:20:15)