题目17: 单调递增最长子序列
2013-03-25 22:25
302 查看
单调递增最长子序列
时间限制:3000 ms | 内存限制:65535 KB难度:4
描述求一个字符串的最长递增子序列的长度
如:dabdbf最长递增子序列就是abdf,长度为4
输入第一行一个整数0<n<20,表示有n个字符串要处理
随后的n行,每行有一个字符串,该字符串的长度不会超过10000
输出输出字符串的最长递增子序列的长度
样例输入
3 aaa ababc abklmncdefg
样例输出
1 3 7
来源
经典题目
/********************************* * 日期:2013-3-25 * 作者:SJF0115 * 题号: 题目17: 单调递增最长子序列 * 来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=17 * 结果:AC * 来源:南阳理工OJ * 总结: **********************************/ #include<stdio.h> #include<string.h> char array[10001]; int MaxLen[10001]; //最长递增子序列 void LIS(){ memset(MaxLen,0,sizeof(MaxLen)); int len = strlen(array); for(int i = 0;i < len;i++){ MaxLen[i] = 1; for(int j = 0;j < i;j++){ if(array[i] > array[j]){ if(MaxLen[i] < 1 + MaxLen[j]){ MaxLen[i] = 1 + MaxLen[j]; } } } } } int main() { int N,i,len,Max; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); scanf("%d",&N); //N组测试数据 while(N--){ Max = 0; scanf("%s",array); LIS(); len = strlen(array); //输出最大长度 for(i = 0;i < len;i++){ if(Max < MaxLen[i]){ Max = MaxLen[i]; } } printf("%d\n",Max); } return 0; }
具体参考:点击打开链接
相关文章推荐
- 【NYOJ】题目17单调递增最长子序列
- NYOJ 题目17 单调递增最长子序列 (DP)
- NYOJ 题目17 单调递增最长子序列 (DP) hdu 题目2845 Bean
- 题目17:单调递增最长子序列
- 南阳理工OJ_题目17 单调递增最长子序列
- NYOJ 题目17 单调递增最长子序列(动态规划)
- nyoj 题目17 单调递增最长子序列
- NYOJ 题目17 单调递增最长子序列
- NYOJ 17 单调递增最长子序列
- NYOJ 17 单调递增最长子序列
- 单调递增最长子序列nyoj17
- NYOJ 17 单调递增最长子序列(基础dp)
- nyoj 17 单调递增最长子序列
- nyoj17单调递增最长子序列(N*logN)
- nyoj 17 单调递增最长子序列
- 单调递增最长子序列--动态规划的经典题目
- nyoj 17 单调递增最长子序列
- NYOJ-17-单调递增最长子序列
- NYOJ17,单调递增最长子序列
- NYOJ17 单调递增最长子序列 【二分法】+【动态规划】