Streat思锥 2016-10-31 14:44 采纳率: 0%
浏览 1183
已结题

CODEVS 1169 传纸条 有两个点过不去 求助大神!!!!

#include<stdio.h>
#include<iostream>
using namespace std;
int m,n,a[55][55],f[80][80][80][80];
int maxx(int a,int b){return a>b?a:b;} 
int d(int x1,int y1,int x2,int y2){
    if(f[x1][y1][x2][y2]>0) return f[x1][y1][x2][y2];
    else if(x1==m&&y1==n-1&&x2==m-1&&y2==n) return f[x1][y1][x2][y2]=a[x1][y1]+a[x2][y2];
    else{
        int t1x1=x1+1,t1y1=y1 , t2x1=x1,t2y1=y1+1 , t1x2=x2+1,t1y2=y2 , t2x2=x2,t2y2=y2+1,i=0,j=0,k=0,l=0,mmax=0;
        if(t1x1<=m&&t1x2<=m) 
            i=d(t1x1,t1y1,t1x2,t1y2)+a[x1][y1]+a[x2][y2];
        if(t1x1<=m&&t2y2<=n) 
            j=d(t1x1,t1y1,t2x2,t2y2)+a[x1][y1]+a[x2][y2];
        if(t2y1<=n&&t1x2<=m&&((t1x2!=t2x1)||(t1y2!=t2y1))) 
            k=d(t2x1,t2y1,t1x2,t1y2)+a[x1][y1]+a[x2][y2];
        if(t2y1<=n&&t2y2<=m) 
            l=d(t2x1,t2y1,t2x2,t2y2)+a[x1][y1]+a[x2][y2];
        mmax=maxx(maxx(i,j),maxx(k,l));
        return f[x1][y1][x2][y2]=mmax;
    }
}
int main(){
    freopen("1169.in","r",stdin);
    freopen("1169.out","w",stdout);
    cin>>m>>n;
    for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
    cout<<d(2,1,1,2);
    return 0;
}

解释:开始和回来必经过(1,2)和(2,1) 到达和回来必经过(m,n-1)和(m-1,n)
让(x1,y1)从(2,1)、(x2,y2)从(1,2)开始搜索
(t1x1,t1y1)表示(x1,y1)向下搜索,(t2x1,t2y1)表示(x1,y1)向右搜索,(t1x2,t1y2)表示(x2,y2)向下搜索,(t2x2,t2y2)表示(x2,y2)向右搜索。
下面是错误的一个点:
你的答案
1c1
你的答案
4348
\ No newline at end of file
正确答案
4419
输入数据 (只显示前20行,完整数据请点击上面按钮下载)
18 20
0 32 89 70 89 55 71 79 40 10 64 80 30 19 62 67 98 42 8 32
57 27 22 1 38 89 52 74 43 8 2 65 82 20 67 22 43 22 95 16
48 25 6 75 86 96 3 85 43 69 93 4 61 53 81 43 84 20 15 34
22 35 26 28 33 67 19 79 19 45 8 13 51 0 86 68 18 47 82 3
16 80 0 18 39 22 5 26 65 70 21 92 66 65 14 6 46 46 21 32
80 35 86 6 67 29 42 71 14 77 55 3 1 14 38 71 82 41 65 12
5 77 3 67 22 59 40 81 48 63 63 25 45 32 78 83 26 96 18 99
45 56 31 30 45 47 80 1 7 81 18 1 90 15 71 22 69 44 18 31
60 16 93 13 17 44 97 98 51 46 42 22 47 72 97 24 52 55 59 25
100 28 5 14 76 32 41 97 61 32 20 0 2 8 41 52 77 35 22 98
78 92 68 29 82 33 28 16 5 9 21 13 26 39 59 69 10 42 4 13
80 34 42 100 44 32 70 15 32 8 83 10 23 73 8 53 7 21 10 52
14 82 28 24 33 94 59 4 17 73 53 85 31 100 74 74 12 72 38 34
14 22 53 0 30 95 3 52 79 41 36 81 25 24 67 48 95 44 7 96
77 90 48 92 45 78 93 95 38 71 4 83 79 64 89 0 76 81 34 66
1 13 58 4 40 5 24 17 6 65 13 13 76 3 20 8 36 12 60 37
42 53 87 10 65 42 25 47 41 33 71 69 94 24 12 92 11 71 3 82
91 90 20 95 44 76 60 34 .

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-10-31 14:52
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable