1 #include<stdio.h>
 2 #include<string.h>
 3 int dp[1000005],pre[1000005],a[1000005];
 4 int main()
 5 {
 6     int max1;
 7     int i,j,n,m;
 8     while (~scanf("%d%d",&m,&n))
 9     {
10         for (i=1;i<=n;i++) scanf("%d",&a[i]);
11         memset(dp,0,sizeof(dp));
12         memset(pre,0,sizeof(pre));
13         max1=-0x3f3f3f3f;
14         for (i=1;i<=m;i++)
15         {
16             max1=-0x3f3f3f3f;
17             for (j=i;j<=n;j++)
18             {
19                 if (dp[j-1]>pre[j-1]) dp[j]=dp[j-1]+a[j];
20                                  else dp[j]=pre[j-1]+a[j];
21                 pre[j-1]=max1;
22                 if (dp[j]>max1) max1=dp[j];
23             }
24         }
25         printf("%d\n",max1);
26     }
27     return 0;
28 }

http://acm.hdu.edu.cn/showproblem.php?pid=1024

相关文章:

  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-01-25
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-05-26
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
相关资源
相似解决方案