Sdut3146:integer Division 2 (integer divide interval dp)

Source: Internet
Author: User
Tags integer division

Title: Portal

The title describes this was a very simple problem, just like previous one. You is given a postive integer n, and you need to divide this integer into m pieces. Then multiply the M pieces together. There is many a-do. But Shadow95 want to know the maximum result of you can get. Input first line is a postive integer t, means there is t-test case S.following T lines, each line there is the integer n, M. (0<=n<=10^18, 0 < m < log10 (n)) output the Maximu M result you can get. Example input
1123 2
Sample output
36
Tip You can divide "123" to "a" and "3". Then the maximum result is 12*3=36. Test instructions is very simple, but I was a slag, DP in the game never had a, decisive or look at the problem, but also only this type, other types of interval DP decisive or not, decisive can not extrapolate ah. The code is as follows:
#include <iostream>#include<algorithm>#include<stdio.h>#include<string.h>typedefLong Longll;using namespacestd;#defineMoD 1000000007intm,l;Chars[ A];//local variables are completely different from global variables for string lengthsll a[ -][ -],dp[ -][ -];intMain () {intT; scanf ("%d",&T);  while(t--) {scanf ("%s", s+1); scanf ("%d",&m); L=strlen (s+1); Memset (A,0,sizeof(a)); if(m==1|| m==0) {printf ("%s\n", s+1); Continue; }         for(intI=1; i<=l;i++)        {             for(intj=i;j<=l;j++) {A[i][j]=a[i][j-1]*Ten+ (s[j]-'0'); }} memset (DP,0,sizeof(DP));  for(intI=0; i<=l;i++) dp[i][1]=a[1][i];  for(intj=2; j<=m;j++)        {             for(inti=j;i<=l;i++)            {                 for(intk=1; k<i;k++) {Dp[i][j]=max (dp[i][j],dp[k][j-1]*a[k+1][i]); }}} printf ("%lld\n", Dp[l][m]); }    return 0;} 

Sdut3146:integer Division 2 (integer divide interval dp)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.