首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

(DP6.1.4.1)UVA 111History Grading(最长递加子序列LIS 的LCS 解法)

2013-10-14 
(DP6.1.4.1)UVA 111History Grading(最长递增子序列LIS 的LCS 解法)/* * UVA_111.cpp * *Created on: 2013

(DP6.1.4.1)UVA 111History Grading(最长递增子序列LIS 的LCS 解法)

/* * UVA_111.cpp * *  Created on: 2013年10月13日 *      Author: Administrator */#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;const int maxn = 25;int f[maxn][maxn];int st[maxn];int ed[maxn];int main(){int n;scanf("%d",&n);int i,j;for(i = 1 ; i <= n ; ++i){int a;cin >> a;st[a] = i;}while(!cin.eof()){for(i = 1 ; i <= n ; ++i){int a;cin >> a;ed[a] = i;}if(cin.eof()){break;}memset(f,0,sizeof(f));for(i = 1 ; i <= n ; ++i){for(j = 1 ; j <= n ; ++j){f[i][j] = max(f[i-1][j],f[i][j-1]);if(st[i] == ed[j]){f[i][j] = max(f[i][j],f[i-1][j-1] + 1);}}}printf("%d\n",f[n][n]);}return 0;}

1楼u012428502昨天 17:21
event.weibo.com/2768516nevent.weibo.com/2768542nevent.weibo.com/2768560nevent.weibo.com/2768612nevent.weibo.com/2768638nevent.weibo.com/2769356nevent.weibo.com/2769422nevent.weibo.com/2769444nevent.weibo.com/2769460nevent.weibo.com/2769490nevent.weibo.com/2769650nevent.weibo.com/2769676nevent.weibo.com/2769740nevent.weibo.com/2769772nevent.weibo.com/2769788nevent.weibo.com/2769842nevent.weibo.com/2769872nevent.weibo.com/2769890nevent.weibo.com/2770008

热点排行