fjnu 1658 Common Subsequence
来源:互联网 发布:逆战异地登录数据异常 编辑:程序博客网 时间:2024/04/27 06:58
Description
Sample Input
abcfbc abfcabprogramming contest abcd mnp
Sample Output
420
KEY:这题就求最长递增子序列的问题,不是什么难题,可是老是TLE,居然是因为空间给小了……无语~
Source:
#include<stdio.h>
#include<string.h>
int max(int a,int b)
...{
if(a>=b) return a;
else return b;
}
void GetList(char str1[],char str2[])
...{
int la=strlen(str1)-1;
int lb=strlen(str2)-1;
int i,j;
int f[1000][1000]=...{0};
for(i=1;i<=la;i++)
for(j=1;j<=lb;j++)
...{
if(str1[i]==str2[j])
...{
f[i][j]=f[i-1][j-1]+1;
}
else
...{
f[i][j]=max(f[i-1][j],f[i][j-1]);
}
}
printf("%d ",f[la][lb]);
}
int main()
...{
/**//* freopen("fjnu_1658.in","r",stdin);*/
char str1[1000],str2[1000],t1[1000],t2[1000];
strcpy(str1,"#");
strcpy(str2,"#");
while(scanf("%s%s",t1,t2)!=EOF)
...{
strcat(str1,t1);
strcat(str2,t2);
GetList(str1,str2);
strcpy(str1,"#");
strcpy(str2,"#");
}
return 0;
}
#include<stdio.h>
#include<string.h>
int max(int a,int b)
...{
if(a>=b) return a;
else return b;
}
void GetList(char str1[],char str2[])
...{
int la=strlen(str1)-1;
int lb=strlen(str2)-1;
int i,j;
int f[1000][1000]=...{0};
for(i=1;i<=la;i++)
for(j=1;j<=lb;j++)
...{
if(str1[i]==str2[j])
...{
f[i][j]=f[i-1][j-1]+1;
}
else
...{
f[i][j]=max(f[i-1][j],f[i][j-1]);
}
}
printf("%d ",f[la][lb]);
}
int main()
...{
/**//* freopen("fjnu_1658.in","r",stdin);*/
char str1[1000],str2[1000],t1[1000],t2[1000];
strcpy(str1,"#");
strcpy(str2,"#");
while(scanf("%s%s",t1,t2)!=EOF)
...{
strcat(str1,t1);
strcat(str2,t2);
GetList(str1,str2);
strcpy(str1,"#");
strcpy(str2,"#");
}
return 0;
}
- fjnu 1658 Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- Common Subsequence
- 调度算法
- widget小砍2
- 函数式编程另类指南
- 算法(李开复)
- 去除图片链接边框及其链接虚线
- fjnu 1658 Common Subsequence
- 设计模式中创建型模式 (二):原型模式
- Winform 系统调优
- 用Java读取ico文件,使用ico图标
- tuxedo之用WTC和weblogic互接
- MonoDevelop 1.0正式发布!
- 团队建设与沟通——善用“鼓励”
- 构建 arm-linux 仿真运行环境 (skyeye + arm-linux + NFS)
- u-boot移植三