單調遞增連續最長子序列

來源:互聯網
上載者:User

標籤:style   color   io   os   ar   for   sp   div   on   

描述
求一個字串的最長遞增子序列[字母保持原順序連續]的長度
如:dabdbf最長遞增子序列就是abd,長度為3
輸入
第一行一個整數0<n<20,表示有n個字串要處理
隨後的n行,每行有一個字串,該字串的長度不會超過10000
輸出
輸出字串的最長遞增字典序的長度[序列字元保持連續]
範例輸入
3aaaababcabklmncdefg
範例輸出
136
#include<stdio.h>#include<string.h>int main(){int n;char str[10010];scanf("%d",&n);getchar();while(n--){int i=0,j,max=0;gets(str);int len=strlen(str);for(;i<len;++i){for(j=i;j<len-1;++j){if(str[j]>=str[j+1]){max=max<j-i+1?j-i+1:max;i=j;break;}}if(j==len-1){max=max<len-i?len-i:max;//printf("max=%d##i=%d##len=%d\n",max,i,len);break;}}printf("%d\n",max);}return 0;}
改編自nyoj-17-單調自增最長子序列

單調遞增連續最長子序列

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.