A0524和A0531的代码相似度

~ 2024-12-31 21:05:16

A0524:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dpmin[410][410],n;
int a[410],sum[410],minn = 1e9;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
	}
	for (int i = 1;i <= n;i++)
	{
		sum[i] = sum[i - 1] + a[i];
	}
	for (int i = 0;i < 410;i++)
		for (int j = 0;j < 410;j++)
			if (i != j) dpmin[i][j] =1e9;
	for(int len = 2; len <= n; len++)
    {
        for(int i = 1; i + len - 1 <= n; i++)
        {
            int j = i + len - 1;
            for(int k = i; k < j; k++)
            {
                dpmin[i][j] = min(dpmin[i][j],dpmin[i][k] + dpmin[k + 1][j] + sum[j] - sum[i - 1]);
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        minn = min(minn, dpmin[i][i + n - 1]);
    }
    cout << minn << '\n';
	return 0;
}

A0531:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dpmin[410][410],dpmax[410][410],n;
int a[410],sum[410],minn = 1e9,maxx;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		a[i+n] = a[i];
	}
	for (int i = 1;i <= n* 2;i++)
	{
		sum[i] = sum[i - 1] + a[i];
	}
	for (int i = 0;i < 410;i++)
		for (int j = 0;j < 410;j++)
			if (i != j) dpmin[i][j] =1e9;
	for(int len = 2; len <= 2 * n; len++)
    {
        for(int i = 1; i + len - 1 <= 2 * n; i++)
        {
            int j = i + len - 1;
            for(int k = i; k < j; k++)
            {
                dpmin[i][j] = min(dpmin[i][j],dpmin[i][k] + dpmin[k + 1][j] + sum[j] - sum[i - 1]);
                dpmax[i][j] = max(dpmax[i][j],dpmax[i][k] + dpmax[k + 1][j] + sum[j] - sum[i - 1]);
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        minn = min(minn, dpmin[i][i + n - 1]);
        maxx = max(maxx, dpmax[i][i + n - 1]);
    }
    cout << minn << '\n';
    cout << maxx << '\n';	
	return 0;
}

你就说像不像!!!!!!!!!!!!!!



我们会审查剪贴板内容,并对发布不合适内容的同学进行相应的处理