hdu-1159 裸LCS
来源:互联网 发布:淘宝自然堂是正品吗 编辑:程序博客网 时间:2024/05/22 17:14
把dp边界值的初始化放到二重循环里,代码看上去真是优雅呢!
#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <iostream>#include <cmath>#include <vector>#include <algorithm>using namespace std;#define DEBUGconst int maxn=1000+5,maxv=26,INF=0x3f3f3f3f;int n,d[maxn],a[maxn],dp[maxn][maxn];char s1[maxn],s2[maxn];int n1,n2;int main(){#ifdef DEBUG freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);#endif while(scanf("%s",s1+1)!=EOF){ scanf("%s",s2+1); memset(dp,0,sizeof(dp)); n1=strlen(s1+1); n2=strlen(s2+1); for(int i=0;i<=n1;i++){ for(int j=0;j<=n2;j++){ if(i==0){dp[i][j]=0;continue;} if(j==0){dp[i][j]=0;continue;} if(s1[i]==s2[j]){ dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1); } else{ dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } } printf("%d\n",dp[n1][n2]); }#ifdef DEBUG fclose(stdin); fclose(stdout);#endif return 0;}
阅读全文
0 0
- hdu-1159 裸LCS
- hdu 1159 LCS
- hdu 1159 dp - lcs
- HDU 1159 dp(lcs)
- HDU 1159 LCS
- hdu 1159 Common Subsequence (LCS)
- HDU 1159 Common Subsequence(LCS)
- hdu 1159 Common Subsequence(LCS)
- HDU 1159 Common Subsequence【LCS】
- hdu 1159 Common Subsequence (lcs)
- hdu 1159 Common Subsequence(lcs)
- HDU-1159-Common Subsequence【LCS】
- hdu 1159 滚动数组+LCS
- HDU 1159 Common Subsequence(LCS)
- HDU 1159 Common Subsequence(LCS)
- HDU 1159 Common Subsequence (LCS)
- HDU 1159 Common Subsequence (线性dp 裸LCS)
- hdu 1159 LCS最大公共子序列
- react 数据传递
- kaldi学习第一天
- vim常用操作(待编辑)
- 移动端布局字体单位的选择之px、rem和em揭秘
- Operation not permitted
- hdu-1159 裸LCS
- 运行javac -encoding utf-8 **.java 同样报错”编码 GBK 的不可映射字符“
- Lsn5研究ListView源码来封装RecylerView实现添加无数个头布局和尾布局
- 求最大子矩阵的大小(Maximal Rectangle)
- 深入理解HTTP协议
- FZU2253 Salty Fish
- python数据类型之number
- dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
- 错排公式,n封信放入n个信封,要求全部放错