Problem Description
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
 
Author
yifenfei
 
Source
 
题目大意:从(1,1)走到(N,N),每次只能向下或者向右走,然后在走回(1,1)每次只能向上或者向左走。然后每个点上都有一个值,问你途径所能获得的值最大是多少,并且每个点只能走一次。
 
虽然数据范围比较小可以用四维的, 但写这题是为了练习,写了个可以数据范围再稍大点的
 
让两个进程同时进行,枚举步数 k, 当x1==x2 || y1==y2时跳过,得状态转移方程:
dp(k,x1,y1,x2,y2)=max(dp(k-1,x1-1,y1,x2-1,y2),dp(k-1,x1-1,y1,x2,y2-1),dp(k-1,x1,y1-1,x2,y2-1),dp(k-1,x1,y1-1,x2,y2-1))+a(x1,y1)+a(x2,y2);
由于只能走右或下,所以坐标满足x+y=k,这样就能降低维数为3维(y1=k-x1,y2=k-x2),方程:
dp(k,x1,x2)=max(dp(k-1,x1,x2),dp(k-1,x1-1,x2),dp(k-1,x1,x2-1),dp(k-1,x1-1,x2-1)) + a(x1,k-x1)+a(x2,k-x2);
 
 


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL; #define N 110
const LL INF = 1e14;
#define met(a,b) (memset(a,b,sizeof(a)))
#define max4(a,b,c,d) (max(max(a,b),max(c,d))) LL a[N][N], dp[N*][N][N]; int main()
{
int n; while(scanf("%d", &n)!=EOF)
{
int i, j, k; met(a, );
for(k=; k<=n*-; k++)
for(i=; i<=n; i++)
for(j=; j<=n; j++)
dp[k][i][j] = -INF; for(i=; i<=n; i++)
for(j=; j<=n; j++)
scanf("%I64d", &a[i][j]); dp[][][] = a[][];
for(k=; k<=n+n-; k++)
{
for(i=; i<=n; i++) ///i 代表第一个人所在的行
for(j=; j<=n; j++) ///j 代表第二个人所在的行
{
dp[k][i][j] = max4(dp[k-][i][j], dp[k-][i][j-], dp[k-][i-][j], dp[k-][i-][j-]);
if(i!=j)
dp[k][i][j] += a[i][k+-i] + a[j][k+-j];
else
dp[k][i][j] += a[i][k+-i];
}
} printf("%I64d\n", dp[n+n-][n][n]);
}
return ;
}

(多线程dp)Matrix (hdu 2686)的更多相关文章

  1. HDU 2686 Matrix 多线程dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 思路:多线程dp,参考51Nod 1084:http://www.51nod.com/onlin ...

  2. Matrix(多线程dp)

    Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. hdu 2686 Matrix && hdu 3367 Matrix Again (最大费用最大流)

    Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  4. HDU 2686 Matrix 3376 Matrix Again(费用流)

    HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...

  5. codevs1169, 51nod1084(多线程dp)

    先说下codevs1169吧, 题目链接: http://codevs.cn/problem/1169/ 题意: 中文题诶~ 思路: 多线程 dp 用 dp[i][j][k][l] 存储一个人在 (i ...

  6. 51Nod 1084 矩阵取数问题 V2 —— 最小费用最大流 or 多线程DP

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1084 1084 矩阵取数问题 V2  基准时间限制:2 秒 空 ...

  7. 8786:方格取数 (多线程dp)

    [题目描述] 设有N*N的方格图(N<=10),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字0.某人从图的左上角的A 点出发,可以向下行走,也可以向右走,直到到达右下角的B点.在走 ...

  8. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  9. hdu 2686(状压dp)

    题目链接:http://poj.org/problem?id=2686 思路:典型的状压dp题,dp[s][v]表示到达剩下的车票集合为S并且现在在城市v的状态所需要的最小的花费. #include& ...

随机推荐

  1. 关于控制反转(IOC)容器 ,依赖注入(DI)模式必读文章收集

    推荐一篇国外設計大師Martin Fowler的大作:Inversion of Control Containers and the Dependency Injection pattern http ...

  2. (转)OOP(面向对象编程)的几大原则

    文章转载自:http://blog.csdn.net/anders_zhuo/article/details/8949566 设计模式遵循的一般原则: 1.开-闭原则(Open-Closed Prin ...

  3. andorid 列表视图之SimpleAdapter

    .xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android=&qu ...

  4. php中static静态关键字的使用方法和应用场景

    php中除了常规类和方法的使用,访问控制之外,还有静态关键字static,静态变量可以是局部变量也可以是全局变量,当一个程序段执行完毕时,静态变量并没有消失,它依然存在于内存中,下次在定义时还是以前的 ...

  5. ubuntu如何实现双屏显示

    转载自https://blog.csdn.net/tianmaxingkong_/article/details/50570538

  6. Python之路(第十九篇)hashlib模块

    一.hashlib模块 HASH Hash,一般翻译做“散列”,也有直接音译为”哈希”的,就是把任意长度的输入(又叫做预映射,pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值 ...

  7. Python之路番外(第三篇):Pycharm的使用秘籍

    版本:Pycharm2017.3.4Professional Edition 一.Pycharm的基本使用1.在Pycharm下为你的python项目配置python解释器 file --settin ...

  8. Linq去重 不用实现IEqualityComparer接口的方法超级简单

    RskFactorRelation.Instance.GetCache<RskFactorRelation>(true).Where(x => !string.IsNullOrEmp ...

  9. idea maven 创建webapp项目没有src目录

    archetypeCatalog=internal

  10. python之web开发“三剑客”

    #  django import django #  flask import flask # tornado import tornado