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. js倒计时跳转页面实现

  2. 网站文章分享到微博,微信、qq空间--举例用织梦

    有对应接口的,传递参数过去就行了,注意下面的{..},需要替换为你的内容,看参数名称你应该知道是什么东东 新浪地址接口http://service.weibo.com/share/share.php? ...

  3. Liunx history

    Linux中history历史命令使用方法详解   (转) 作者:青藤园来源:|2012-05-10 10:     http://os.51cto.com/art/201205/335040.htm ...

  4. HDU_1142(最短路 + dfs)

    Jimmy experiences a lot of stress at work these days, especially since his accident made working dif ...

  5. POJ2728 Desert King

    一道生成树+\(0/1\)分数规划 原题链接 设每条边的距离为\(dis[x]\),两点高度差为\(h[x]\),该图的生成树为\(T\),则题目实际求的就是\(\dfrac{\sum\limits_ ...

  6. UISwitch开关控件属性介绍以及获取开关状态并做出响应

    (1)UISwitch的大小也是固定的,不随我们frame设置的大小改变:也是裁剪成圆角的,设置背景就露马脚发现背景是矩形. (2)UISwitch的背景图片设置无效,即我们只能设置颜色,不能用图片当 ...

  7. delphi 7 求无码

    我们知道delphi很多源码,都是没有提供的,比如BDE,一旦有问题,我们也找不到办法解决,那么那些dcu对应的pas是没有公布的呢?笔者做了个统计. 下面是delphi7 的,如果你的程序有用到没有 ...

  8. dbc file

    DBC文件是用来描述CAN网络通信信号的一种格式文件.它可以用来监测与分析CAN网络上的报文数据,也可以用来模拟某个CAN节点.(DBC file is a format file used to d ...

  9. Collection和Collections的区别是什么

    1)java.util.Collection是一个集合顶层接口,该接口的设计目的是为各种具体的集合提供最大化的统一的操作方式,它提供了对集合对象进行基本操作的通用接口方法,实现该接口的类主要有List ...

  10. 用php脚本比较MySQL两个数据库的结构差异

    define('DATABASE1', 'mysql://root:password@127.0.0.1/db1'); $dbi1 = new DbMysql; $dbi1->dbh = DAT ...