多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 杭電1159(Common Subsequence)LCS和dp

杭電1159(Common Subsequence)LCS和dp

來源:程序員人生   發布時間:2015-06-16 08:44:58 閱讀次數:3563次

點擊打開杭電1159

Problem Description
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence <i1, i2, ..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
 

Sample Input
abcfbc abfcab programming contest abcd mnp
 

Sample Output
4 2 0


代碼實現:

import java.util.*; class Main { static int[][] dp; public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str1=sc.next(); String str2=sc.next(); lcs(str1,str2); System.out.println(dp[str1.length()][str2.length()]); } } public static void lcs(String str1,String str2){ int i,j; dp=new int[str1.length()+1][str2.length()+1]; for(i=1;i<=str1.length();i++){ for(j=1;j<=str2.length();j++){ if(str1.charAt(i⑴)==str2.charAt(j⑴)){ dp[i][j]=dp[i⑴][j⑴]+1; }else{ dp[i][j]=Math.max(dp[i⑴][j], dp[i][j⑴]); } } } } }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日本一区二区在线不卡 | 性色a∨人人爽网站 | 色婷婷影院在线视频免费播放 | 精品午夜国产在线观看不卡 | 亚洲另类精品xxxx人妖 | 成人精品视频一区二区在线 | 18在线网站 | 日韩精品欧美成人 | 久久国产精品免费一区二区三区 | 欧美一级毛片大片免费播放 | 亚洲免费闲人蜜桃 | 欧美性猛交xxxx黑人喷水 | 亚洲专区一路线二 | 久久国内精品视频 | 久久国产精品一区二区三区 | 欧美高清欧美videosex | 欧洲一区二区 | 美国一级特级毛片片aa视频 | 亚洲成人在线播放 | 国产xxxxx| 又做又爱高清免费观看 | 国产精品反差婊在线观看 | 精品一区二区三区在线视频 | 久久久国产这里有的是精品 | 亚洲天堂影视 | 久久精品蜜芽亚洲国产a | 伊人网99 | 欧美另类videosbestse | 国产精品2020观看久久 | 宇都宫紫苑在线观看 | 欧美国产综合日韩一区二区 | 视频在线免费观看 | 日韩精品欧美亚洲高清有无 | 免费jizz在线播放视频高清版 | 日本特黄特色aa大片免费 | 成人不卡视频 | 色琪琪永久远网址 | 亚洲 中文 欧美 日韩 在线人 | 日本在线不卡一区二区 | 国产亚洲精品久久综合影院 | 久久精品一品道久久精品9 久久精品一区二区 |