2 条题解

  • 0
    @ 2021-10-20 19:52:39
    
    /*****************************************
    Note  : 
    ******************************************/
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define LL long long
    const int N = 100 + 10;
    const int INF = 0x3f3f3f3f;
    struct node
    {
    	int a[N];
    	node()
    	{
    		memset(a,0,sizeof(a));
    	}
    	void operator = (const node &s)
    	{
    		memcpy(a,s.a,sizeof(s.a));
    	}
    	node operator + (const int &s)
    	{
    		node t;
    		t.a[0] += s;
    		for(int i = 0 ; i < 50 ; i++)
    		{
    			t.a[i] += a[i];
    			t.a[i+1] += t.a[i]/10;
    			t.a[i] %= 10;
    		}
    		return t;
    	}
    	node operator + (const node &s)
    	{
    		node t;
    		for(int i = 0 ; i <= 50 ; i++)
    		{
    			t.a[i] += a[i] + s.a[i];
    			t.a[i+1] += t.a[i]/10;
    			t.a[i] %= 10;
    		}
    		return t;
    	}
    	node operator * (const node &s)
    	{
    		node t;
    		for(int i = 0 ; i < 50 ; i++)
    			for(int j = 0 ; j < 50 ; j++)
    			{
    				t.a[i+j] += a[i] * s.a[j];
    				t.a[i+j+1] += t.a[i+j]/10;
    				t.a[i+j] %= 10;
    			}
    			return t;
    	}
    	node operator << (const int &s)
    	{
    		node t;
    		for(int i = 50 ; i >= 0 ; i--)
    			t.a[i+s] = a[i];
    		return t;
    	}
    	bool operator < (const node &s)
    	{
    		for(int i = 50 ; i >= 0 ; i--)
    			{
    				if(a[i] < s.a[i])	return true;
    				else if(a[i] > s.a[i])	return false;
    			}
    			return false;
    	}
    	void print()
    	{
    		int len = N - 1;
    		while(a[len] == 0 && len > 0)
    			len--;
    		for(int i = len ; i >= 0 ; i--)
    			cout << a[i];
    		cout << endl;
    	}
    };
    int n , k;
    char num[100];
    node x , sum[N][N] , dp[N][N];
    int main()
    {
    	cin >> n >> k;
    	cin >> num;
    	for(int i = 0 ; i < n ; i++)
    		x.a[i] = num[i] - '0';
    	for(int i = 0 ; i < n ; i++)
    		for(int j = i ; j < n ; j++)
    			if(i == j)
    				sum[i][j].a[0] = x.a[j];
    			else
    				sum[i][j] = (sum[i][j-1] << 1) + x.a[j];
    
    	for(int i = 0 ; i <= k ; i++)
    		for(int j = 0 ; j <= n ; j++)
    			dp[j][i].a[0] = 1;
    
    	for(int i = 0 ; i < n ; i++)
    		dp[i][0] = sum[0][i];
    
    	for(int l = 1 ; l <= k ; l++)
    		for(int i = l ; i < n ; i++)
    			for(int j = l-1 ; j < i ; j++)
    				if(dp[i][l] < dp[j][l-1] * sum[j+1][i])
    					dp[i][l] = dp[j][l-1] * sum[j+1][i];
    
    	dp[n-1][k].print();
        return 0;
    }
    ```c

    信息

    ID
    645
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    递交数
    68
    已通过
    19
    上传者