1 solutions

  • 0
    @ 2024-12-11 0:49:30

    C++ :

    #include<iostream>
    #include<string>
    using namespace std;
    const int N=100;
    int f[N][N],a[N][N]={0};
    int main()
    {
    	int n,m;
    	string s;
    	cin>>n>>m>>s;
    	for(int i=1;i<=n;i++)
    	 for(int j=i;j<=n;j++)
    	  a[i][j]=a[i][j-1]*10+s[j-1]-'0';
    	for(int i=1;i<=n;i++) f[i][0]=a[1][i];
    	for(int k=1;k<=m;k++)
    	 for(int i=k+1;i<=n;i++)
    	  for(int j=k;j<i;j++)
    	   f[i][k]=max(f[i][k],f[j][k-1]*a[j+1][i]);
    	cout<<f[n][m]<<endl;
    	return 0;
    }
    

    Pascal :

    var a:array[0..40] of integer;
        f,num:array[0..100,0..100] of qword;
        s,t,i,j,k,l,n,max,code:longint;
        c:char;
    begin
      readln (n,l);
      for i:=1 to n do
        begin
          read(c);
          val(c,a[i],code);
        end;
      for i:=1 to n do
        for j:=i to n do
          begin
            s:=0;
            for k:=i to j do s:=s*10+a[k];
            num[i,j]:=s;
          end;
      for i:=1 to n do
        begin
          f[i,0]:=num[1,i];
          for j:=1 to l do
            begin
              max:=0;
                for k:=2 to i do
                  begin
                    t:=f[k-1,j-1]*num[k,i];
                    if t>max then max:=t;
                  end;
              f[i,j]:=max;
            end;
        end;
      writeln(f[n,l]);
    end.
    
    
    
    • 1

    Information

    ID
    741
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By