UVa 10069 - Distinct Subsequences
来源:互联网 发布:手机淘宝网店怎么登陆 编辑:程序博客网 时间:2024/04/30 09:26
高精度的运算,,所以用了JAVA的大数。
用b表示长串,a表示短串。dp[k][j]表示的是短串的位置k之前的子串在长串位置j之前出现的次数。
所以当str[j] == str[k] dp[k][j] += dp[k - 1][j - 1]
不过在对dp[k][j]进行初始化的时候要特别注意
import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner cin = new Scanner ( System.in );int Case;Case = cin.nextInt();for ( int i = 1; i <= Case; ++i ) {char b[] = cin.next().toCharArray();char a[] = cin.next().toCharArray();BigInteger dp[][] = new BigInteger[105][10005];for ( int k = 0; k < dp.length; ++k ) for ( int j = 0; j < dp[k].length; ++j )dp[k][j] = BigInteger.ZERO;for ( int k = 0; k < b.length; ++k ) {if ( k > 0 ) dp[0][k] = dp[0][k - 1];if ( b[k] == a[0] ) dp[0][k] = dp[0][k].add ( BigInteger.ONE );}for ( int k = 1; k < a.length; ++k ) {for ( int j = k; j < b.length; ++j ) {dp[k][j] = dp[k][j - 1];if ( a[k] == b[j] ) dp[k][j] = dp[k][j].add( dp[k - 1][j - 1] );}}System.out.println ( dp[a.length - 1][b.length - 1] );}}}
- uva 10069 Distinct Subsequences
- UVA 10069 Distinct Subsequences
- UVa 10069 - Distinct Subsequences
- UVa 10069 - Distinct Subsequences
- UVa 10069 - Distinct Subsequences
- uva 10069 - Distinct Subsequences
- UVa 10069 - Distinct Subsequences
- Uva-10069-Distinct Subsequences
- UVA - 10069 Distinct Subsequences
- UVa:10069 Distinct Subsequences
- UVa 10069 - Distinct Subsequences
- uva 10069 Distinct Subsequences
- UVA-10069 - Distinct Subsequences
- UVA - 10069 Distinct Subsequences
- UVa 10069 - Distinct Subsequences
- UVA 10069 Distinct Subsequences
- uva 10069 - Distinct Subsequences
- UVa Problem 10069 Distinct Subsequences
- 用Matlab处理Dicom图像
- Palindrome Partitioning I
- Android 下通过jni读取i2c数据
- 时间字段的读取
- css中的*代表对所有控件起作用
- UVa 10069 - Distinct Subsequences
- Eclipse用法和技巧七:自动生成get和set方法2
- 客户端数据校验器
- 操作系统μC/OS-II的特点
- android 工程开发问题Failed java.util.EmptyStackException
- "*.exe不是有效的Win32程序" 解决办法
- UVa 10911 - Forming Quiz Teams
- firefox不能显示下载进度窗口
- PKG_CONFIG_PATH