• HDU 2686 Matrix


    Matrix

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 2686
    64-bit integer IO format: %I64d      Java class name: Main
    Yifenfei very like play a number game in the n*n Matrix. A positive integer number is put in each area of the Matrix.
    Every time yifenfei should to do is that choose a detour which frome the top left point to the bottom right point and than back to the top left point with the maximal values of sum integers that area of Matrix yifenfei choose. But from the top to the bottom can only choose right and down, from the bottom to the top can only choose left and up. And yifenfei can not pass the same area of the Matrix except the start and end. 
     

    Input

    The input contains multiple test cases.
    Each case first line given the integer n (2<n<30) 
    Than n lines,each line include n positive integers.(<100)
     

    Output

    For each test case output the maximal values yifenfei can get.
     

    Sample Input

    2
    10 3
    5 10
    3
    10 3 3
    2 5 3
    6 7 10
    5
    1 2 3 4 5
    2 3 4 5 6
    3 4 5 6 7
    4 5 6 7 8
    5 6 7 8 9

    Sample Output

    28
    46
    80

    Source

     
    解题:传说中的双进程dp
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int dp[80][40][40],val[40][40],n;
     4 int main() {
     5     while(~scanf("%d",&n)) {
     6         memset(dp,0,sizeof dp);
     7         for(int i = 0; i < n; ++i)
     8             for(int j = 0; j < n; ++j)
     9                 scanf("%d",val[i] + j);
    10         for(int k = 1; k < 2*n - 2; ++k) {
    11             for(int i = 0; i < n; ++i)
    12                 for(int j = 0; j < n; ++j) {
    13                     if(i == j) continue;
    14                     dp[k][i][j] = max(max(dp[k-1][i][j],dp[k-1][i-1][j]),max(dp[k-1][i][j-1],dp[k-1][i-1][j-1]));
    15                     dp[k][i][j] += val[i][k - i] + val[j][k - j];
    16                 }
    17         }
    18         int t = 2*n-3;
    19         printf("%d
    ",max(dp[t][n-1][n-2],dp[t][n-2][n-1]) + val[0][0] + val[n-1][n-1]);
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    【转】验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。
    【转】在控制台、WinForm项目中的嵌入mdf文件的烦恼
    【转】ADB server didn't ACK
    【转】android中AVD的使用
    【转】你不可以不知道的findViewById
    【转】Android中的view
    【转】c# 如何获取项目的根目录
    TYVJ 1452 最大权闭合图
    NOIP 最后的总结
    POJ 2396 有上下界的可行流
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4925131.html
Copyright © 2020-2023  润新知