3278 最小m 段和问题

 

 时间限制: 1 s
 空间限制: 256000 KB
 题目等级 : 黄金 Gold
    题目描述 Description

    给定 n 个整数(不一定是正整数)组成的序列,现在要求将序列分割为 m 段,每段子序列中的数在原序列 中连续排列。如何分割才能使这 m 段子序列的和的最大值达到最小?

    输入描述 Input Description

     文件的第 1 行中有 2 个正整数 n 和 m。 正整数 n 是序列 的长度;正整数 m 是分割的断数。 接下来的一行中有 n 个整数。

    输出描述 Output Description

    文件的第 1 行中的数是计算出 的 m 段子序列的和的最大值的最小值。

    样例输入 Sample Input

    1 1

    10

    样例输出 Sample Output

    10

    数据范围及提示 Data Size & Hint

    N<=1000,M<=N

    分类标签 Tags 点此展开 

    注意:
    代码:
    #include< iostream >
    using namespace std;
    #include< cstdio >
    #include< cstring >
    #define INFn 1001
    int n,m,dp[INFn][INFn],sum[INFn],num[INFn];
    void input()
    {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
    scanf("%d",&num[i]);
    sum[i]=sum[i-1]+num[i];
    }
    }
    void DP()
    {
    memset(dp,99,sizeof(dp));
    for(int i=1;i<=n;++i)
    dp[i][1]=sum[i];
    for(int j=2;j<=m;++j)
     for(int i=j;i<=n;++i)
       for(int t=j-1;t<=i-1;++t)
       dp[i][j]=min(dp[i][j],max(dp[t][j-1],sum[i]-sum[t]));
    }
    int main()
    {
    input();
    if(n==0&&m==0)
    {
    cout<<0;
    return 0;
    }
    DP();
    printf("%d",dp[n][m]);
    return 0;
     

    相关文章:

    • 2021-08-08
    • 2022-12-23
    • 2022-12-23
    • 2022-12-23
    • 2022-12-23
    • 2021-06-20
    • 2021-08-23
    • 2022-12-23
    猜你喜欢
    • 2021-06-04
    • 2021-12-27
    • 2021-10-23
    • 2021-10-29
    • 2022-02-25
    • 2021-12-27
    • 2022-12-23
    相关资源
    相似解决方案