/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:26:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
                 for (k=1; k<=m; k++) b[k]=s[j][k]-s[i-1][k]; dp[0][1]=-1000000000;
                 ^~~
/in/foo.cc:26:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
                 for (k=1; k<=m; k++) b[k]=s[j][k]-s[i-1][k]; dp[0][1]=-1000000000;
                                                              ^~
# 状态 耗时 内存占用
#1 Accepted 2ms 320.0 KiB
#2 Accepted 3ms 432.0 KiB
#3 Accepted 2ms 444.0 KiB
#4 Accepted 2ms 464.0 KiB
#5 Accepted 2ms 444.0 KiB
#6 Accepted 2ms 440.0 KiB
#7 Accepted 7ms 572.0 KiB
#8 Accepted 7ms 568.0 KiB
#9 Accepted 124ms 1.055 MiB
#10 Accepted 124ms 1.051 MiB

代码

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <assert.h>
using namespace std;
int n,m,a[305][305],MIN[305],b[305],dp[305][2],i,j,s[305][305],ans,P,k;
int main()
{
    while (cin>>n)
    {
        ans=-1000000000;
        scanf("%d%d",&m,&P); assert(1<=n && n<=300 && 1<=m && m<=300 && -1000<=P && P<=1000);
        for (i=1; i<=n; i++)
          for (j=1; j<=m; j++) {scanf("%d",&a[i][j]); assert(-1000<=a[i][j] && a[i][j]<=1000); }
        for (i=1; i<=n; i++)
          for (j=1; j<=m; j++)
            s[i][j]=s[i-1][j]+a[i][j];
        for (i=1; i<=n; i++)
        {
            for (j=1; j<=m; j++) MIN[j]=a[i][j];
            for (j=i; j<=n; j++)
            {
                for (k=1; k<=m; k++) MIN[k]=min(MIN[k],a[j][k]);
                for (k=1; k<=m; k++) b[k]=s[j][k]-s[i-1][k]; dp[0][1]=-1000000000;
                for (k=1; k<=m; k++) dp[k][0]=max(dp[k-1][0]+b[k],b[k]),dp[k][1]=max(max(dp[k-1][1]+b[k],dp[k-1][0]+b[k]-MIN[k]+P),b[k]-MIN[k]+P);
                for (k=1; k<m; k++) ans=max(ans,max(dp[k][0],dp[k][1]));
                if (i==1 && j==n)
                {
                    ans=max(ans,dp[m][1]); int sum=0;
                    for (k=m; k>1; k--) {sum+=b[k]; ans=max(ans,sum);}
                } else
                  ans=max(ans,max(dp[m][1],dp[m][0]));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

信息

递交者
类型
递交
题目
解密游戏 T3
题目数据
下载
语言
C++
递交时间
2017-10-03 13:55:38
评测时间
2017-10-03 13:55:38
评测机
分数
100
总耗时
278ms
峰值内存
1.055 MiB