2412: Divide the finger

2412: Divide the finger


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
1s8192K373117Standard

We can divide one figure into some smaller ones.For example,123456789 can be divided into 123,456,789,or 1,234567,89,which is similar to putting some boards between the numbers,while the order cannot be changed.Now the figure n is given and should be divided into m parts. Please work out the max product of these m smaller figures.(the first place of n is not 0)

Input

There are muliti test cases.Each case contains two integers n(1=< n < 1,000,000,000,000,000) and m(1=< m <=[lg(n)]),the number n and how many parts n should be divided to.

Output

For each case,just output the max product of the m smaller fingers in a line.

Sample Input

12345 2
12345 3

Sample Output

6170
2460

Hint

For case one,12345 can be divided as 1234|5,or 123|45,or ......
but the max product is 1234*5=6170.

 

Problem Source: provided by tank

 


This problem is used for contest: 87  148 

 

#include<iostream>
#include<cstring>
using namespace std;
char num[100];
double  w[100][100],maxn;
int n,len;
void dfs(int cur_pos,double sum,int total_pos)
{
    int i;
    if(total_pos==n) { if(sum>maxn) maxn=sum; return ;}
    if(cur_pos>=len) return ;
    for(i=cur_pos;i<len;i++) dfs(i+1,sum*w[cur_pos][i],total_pos+1);
}
int main()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    int i,j;
    while(scanf("%s%d",num,&n)==2)
    {
        len=strlen(num);
        for(i=0;i<len;i++)
        {
            w[i][i]=num[i]-'0';
            for(j=i+1;j<len;j++)
            {
                w[i][j]=w[i][j-1]*10+num[j]-'0';
            }
        }
        //for(i=0;i<len;i++) {for(j=0;j<len;j++) printf("%.0lf  .",w[i][j]);printf("/n");}
        maxn=0;
        dfs(0,1,0);
        printf("%.0lf/n",maxn);
    }
    return 0;
}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值