HDU 1159 Common Subsequence
2015-07-22 10:15
190 查看
最长公共子序列
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=1111; int dp[maxn][maxn]; char s[maxn],t[maxn]; int lens,lent; int main() { int i,j; while(~scanf("%s%s",s,t)) { lens=strlen(s); lent=strlen(t); for(i=-1; i<lens; i++) for(j=-1; j<lent; j++) { if(i==-1||j==-1) { dp[i+1][j+1]=0; continue; } if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]); } printf("%d\n",dp[lens][lent]); } return 0; }
相关文章推荐
- 自定义UITableViewCell 上按钮点击事件处理
- 【UIKit】-2- UIAccelerometer-加速计事件
- HDU 5288 OO’s Sequence(多校第一场1001)
- 关于mule中使用jdbc时报No Suitable Driver found错误的问题
- Convert UOM values
- No suitable driver found for jdbc:mysql://localhost:3306/test
- 【UIKit】-1- UIKitDefines.h - 跨平台,包容 C 库
- UISearchBar套接TableView实现搜索功能
- 禁用UITextField的双击出现复制粘贴剪切等操作
- 【Android UI设计与开发】第15期:顶部标题栏(六)实现悬浮式顶部和底部标题栏效果
- IOS中UIview需要知道的一些事情:setNeedsDisplay、setNeedsLayout
- queue的用法以及优先级priority的用法
- hdu contest day1 1001 OO’s Sequence
- IOS 开发之UITableview的基本创建
- OO’s Sequence 2015多校联合1001
- iOS总结控件二(UIButton)
- rabbitmq之back queue草稿
- rabbitmq method之queue.declare
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(四)
- LeetCode N-Queens