标签:stat ring length system exti sys color char import
$dp$,大数运算。
$dp[i][j]$表示到$i$位置切成了$j$段的最大收益。数字爆$longlong$,$Java$上大数。
import java.math.BigInteger; import java.util.Scanner; public class Main { static BigInteger MAX(BigInteger a,BigInteger b) { if(a.compareTo(b)>=0) return a; return b; } public static void main(String args[]){ Scanner cin = new Scanner(System.in); int n,k; String x; BigInteger dp[][] = new BigInteger [50][10]; while(cin.hasNext()) { n = cin.nextInt(); k = cin.nextInt(); k++; x = cin.next(); for(int i=0;i<x.length();i++) { for(int j=1;j<=k;j++) dp[i][j] = BigInteger.ZERO; } String y = ""; for(int i=0;i<x.length();i++) { y=y+x.charAt(i); dp[i][1] = new BigInteger(y); } for(int j=2;j<=k;j++) { for(int i=j-1;i<x.length();i++) { for(int p=j-2;p<i;p++) { y = ""; for(int g=p+1;g<=i;g++) y=y+x.charAt(g); dp[i][j]=MAX(dp[i][j],dp[p][j-1].multiply(new BigInteger(y))); } } } System.out.println(dp[x.length()-1][k]); } } }
标签:stat ring length system exti sys color char import
原文地址:http://www.cnblogs.com/zufezzt/p/6518692.html