zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    top指令
    Trie
    最大公约数
    angular2 获取到的数据无法实时更新的问题
    npm install 的时候出现 write access 导致不能成功安装的问题
    angular 的 @Input、@Output 的一个用法
    windows 安装 apache 服务以及添加 php 解析
    php 性能优化之opcache
    intellij 插件结构(文件结构以及概念层面上的结构)
    jetBrains 插件开发第一课-- 在主菜单栏新增一个菜单
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4925131.html
Copyright © 2011-2022 走看看