为什么错,,,,

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
short n,k[21][21],t,u[21][21];
short dp[21][21][21][21][21][21];
int sum(int a,int b,int c,int d,int e,int f)
{
    if(a<=0||b<=0||c<=0||d<=0||e<=0||f<=0)return 0;
    t=0;
    memset(u,0,sizeof(u));
    if(!u[a][b])t+=k[a][b],u[a][b]=1;
    if(!u[c][d])t+=k[c][d],u[c][d]=1;
    if(!u[e][f])t+=k[e][f],u[e][f]=1;
    return t;
}
short hh(int a,int b,int c,int d,int e,int f)
{
    if(a<=0||b<=0||c<=0||d<=0||e<=0||f<=0)return 0;
    if(dp[a][b][c][d][e][f])return dp[a][b][c][d][e][f];
    if(dp[a][b][e][f][c][d])return dp[a][b][e][f][c][d];
    if(dp[c][d][a][b][e][f])return dp[c][d][a][b][e][f];
    if(dp[c][d][e][f][a][b])return dp[c][d][e][f][a][b];
    if(dp[e][f][a][b][c][d])return dp[e][f][a][b][c][d];
    if(dp[e][f][c][d][a][b])return dp[e][f][c][d][a][b];
    int bt=0;
    bt=max(bt,hh(a,b-1,c,d-1,e,f-1)+sum(a,b-1,c,d-1,e,f-1));
    bt=max(bt,hh(a,b-1,c,d-1,e-1,f)+sum(a,b-1,c,d-1,e-1,f));
    bt=max(bt,hh(a,b-1,c-1,d,e,f-1)+sum(a,b-1,c-1,d,e,f-1));
    bt=max(bt,hh(a,b-1,c-1,d,e-1,f)+sum(a,b-1,c-1,d,e-1,f));
    bt=max(bt,hh(a-1,b,c,d-1,e,f-1)+sum(a-1,b,c,d-1,e,f-1));
    bt=max(bt,hh(a-1,b,c,d-1,e-1,f)+sum(a-1,b,c,d-1,e-1,f));
    bt=max(bt,hh(a-1,b,c-1,d,e,f-1)+sum(a-1,b,c-1,d,e,f-1));
    bt=max(bt,hh(a-1,b,c-1,d,e-1,f)+sum(a-1,b,c-1,d,e-1,f));
    return dp[a][b][c][d][e][f]=bt;
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            cin>>k[i][j];
        }
    dp[1][1][1][1][1][1]=k[1][1];
    cout<<hh(n,n,n,n,n,n)+k[n][n];
}

比较懒,写了个不用脑子的这

0 条评论

目前还没有评论...

信息

ID
1143
难度
4
分类
动态规划 点击显示
标签
递交数
3507
已通过
1452
通过率
41%
被复制
9
上传者