3.28学习总结

完成分割回文串的算法题,难点主要在如何去分割,靠什么去分割字符串

复制代码
int a(char arr[]){
    int i,j;
    int len=strlen(arr);
    for(i=0,j=len-1;i<j;i++,j--){
        if(arr[i]!=arr[j]) return 0;
    }
    return 1;
 }
 char **path;
 int pathtop;
 char***reasult;
 int*ansize;
 int count;
 void copy(){
    char**tempth=(char**)malloc(sizeof(char*)*pathtop);
    int i;
    for(i=0;i<pathtop;i++){
        tempth[i]=path[i];
    }
    reasult[count]=tempth;
    ansize[count++]=pathtop;
 }
 char*cutstring(char*str,int startindex,int endindex){
    char*temp=(char*)malloc(sizeof(char)*(endindex-startindex+2));
    int i;
    int index=0;
    for(i=startindex;i<=endindex;i++){
        temp[index++]=str[i];
    }
    temp[index]='\0';
    return temp;
 }
 void backtracking(char*s,int startindex,int size){
    if(startindex>=size){
      copy();
      return;
    }
    for(int i=startindex;i<size;i++){
        char*temp=cutstring(s,startindex,i);
        if(a(temp)){
            path[pathtop++]=temp;
        }else {
            continue;
        }
        backtracking(s,i+1,size);
        pathtop--;
    }
 }
char*** partition(char* s, int* returnSize, int** returnColumnSizes){
             int len=strlen(s);
             char*** partition(char* s, int* returnSize, int** returnColumnSizes);
             path=(char**)malloc(sizeof(char*)*len);
             reasult=(char***)malloc(sizeof(char**)*40000);
             ansize=(int*)malloc(sizeof(int)*40000);
             pathtop=0;
             count=0;
             backtracking(s,0,len);
             *returnSize=count;
             *returnColumnSizes=(int*)malloc(sizeof(int)*(*returnSize));
             for(int i=0;i<*returnSize;i++){
                (*returnColumnSizes)[i]=ansize[i];
             }
             return reasult;
}

继续跟着写Java的拼图小游戏的项目,感觉对Java的使用更清晰了

相关推荐
CoovallyAIHub7 小时前
Moonshine:比 Whisper 快 100 倍的端侧语音识别神器,Star 6.6K!
深度学习·算法·计算机视觉
CoovallyAIHub8 小时前
速度暴涨10倍、成本暴降6倍!Mercury 2用扩散取代自回归,重新定义LLM推理速度
深度学习·算法·计算机视觉
CoovallyAIHub8 小时前
实时视觉AI智能体框架来了!Vision Agents 狂揽7K Star,延迟低至30ms,YOLO+Gemini实时联动!
算法·架构·github
CoovallyAIHub8 小时前
开源:YOLO最强对手?D-FINE目标检测与实例分割框架深度解析
人工智能·算法·github
CoovallyAIHub8 小时前
OpenClaw:从“19万星标”到“行业封杀”,这只“赛博龙虾”究竟触动了谁的神经?
算法·架构·github
刀法如飞9 小时前
程序员必须知道的核心算法思想
算法·编程开发·算法思想
徐小夕10 小时前
pxcharts Ultra V2.3更新:多维表一键导出 PDF,渲染兼容性拉满!
vue.js·算法·github
CoovallyAIHub11 小时前
OpenClaw一脚踩碎传统CV?机器终于不再只是看世界
深度学习·算法·计算机视觉
CoovallyAIHub11 小时前
仅凭单目相机实现3D锥桶定位?UNet-RKNet破解自动驾驶锥桶检测难题
深度学习·算法·计算机视觉