UVA - 10066 The Twin Towers
来源:互联网 发布:python 外汇行情api 编辑:程序博客网 时间:2024/06/03 17:34
最长公共子序列
#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;int a[110];int b[110];int dp[110][110];int dfs(int i,int j){if(i<0||j<0)return 0;if(dp[i][j]!=-1)return dp[i][j];if(a[i]==b[j])dp[i][j]=dfs(i-1,j-1)+1;elsedp[i][j]=max(dfs(i-1,j),dfs(i,j-1));return dp[i][j];}int main(){int cs=0,n,m,i,j;while(cin>>n>>m){if(n==0||m==0)break;for(i=0;i<n;i++)cin>>a[i];for(i=0;i<m;i++)cin>>b[i];memset(dp,-1,sizeof(dp));dfs(n-1,m-1);printf("Twin Towers #%d\nNumber of Tiles : %d\n\n",++cs,dp[n-1][m-1]);}return 0;}
#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;int a[110];int b[110];int dp[110][110];int main(){int cs=0,n,m,i,j;while(cin>>n>>m){if(n==0||m==0)break;for(i=0;i<n;i++)cin>>a[i];for(i=0;i<m;i++)cin>>b[i];memset(dp,0,sizeof(dp));for(i=1;i<=n;i++)for(j=1;j<=m;j++)if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;elsedp[i][j]=max(dp[i-1][j],dp[i][j-1]);printf("Twin Towers #%d\nNumber of Tiles : %d\n\n",++cs,dp[n][m]);}return 0;}
0 0
- UVA 10066 - The Twin Towers
- uva 10066 The Twin Towers
- UVA 10066 The Twin Towers
- UVA 10066 The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- Uva-10066-The Twin Towers
- UVa:10066 The Twin Towers
- UVa 10066: The Twin Towers
- UVA - 10066 The Twin Towers
- UVa 10066 - The Twin Towers
- UVa 10066 - The Twin Towers
- uva 10066 The Twin Towers
- UVA 10066 - The Twin Towers
- UVA - 10066 The Twin Towers
- UVA 10066 The Twin Towers
- 关于inflate的第3个参数
- WPF学习(第八章) 元素绑定
- 编写一个函数,使给定的一个二维数组(N×N)行列互换(N>3)
- USACO Section 2.2 Preface Numbering
- 第十一周项目一 函数版星号图(2)
- UVA - 10066 The Twin Towers
- android 内存溢出问题分析
- boost::asio::ip::tcp实现网络通信的小例子
- socket sock inet_sock 等关系
- Oracle官方文档结构说明
- 单例下的序列化
- 在ubuntu 12.04 上设置snmp
- 第十一周项目五 当年第几天
- Orale表空间操作理解手记