(多线程dp)Matrix (hdu 2686)
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.
Each case first line given the integer n (2<n<30)
Than n lines,each line include n positive integers.(<100)
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
46
80
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);
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)的更多相关文章
- HDU 2686 Matrix 多线程dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 思路:多线程dp,参考51Nod 1084:http://www.51nod.com/onlin ...
- Matrix(多线程dp)
Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- hdu 2686 Matrix && hdu 3367 Matrix Again (最大费用最大流)
Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 2686 Matrix 3376 Matrix Again(费用流)
HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...
- codevs1169, 51nod1084(多线程dp)
先说下codevs1169吧, 题目链接: http://codevs.cn/problem/1169/ 题意: 中文题诶~ 思路: 多线程 dp 用 dp[i][j][k][l] 存储一个人在 (i ...
- 51Nod 1084 矩阵取数问题 V2 —— 最小费用最大流 or 多线程DP
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1084 1084 矩阵取数问题 V2 基准时间限制:2 秒 空 ...
- 8786:方格取数 (多线程dp)
[题目描述] 设有N*N的方格图(N<=10),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字0.某人从图的左上角的A 点出发,可以向下行走,也可以向右走,直到到达右下角的B点.在走 ...
- hdu 2686 Matrix 最小费用最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...
- hdu 2686(状压dp)
题目链接:http://poj.org/problem?id=2686 思路:典型的状压dp题,dp[s][v]表示到达剩下的车票集合为S并且现在在城市v的状态所需要的最小的花费. #include& ...
随机推荐
- 一位大牛整理的Python资源
Python基本安装: * http://www.python.org/ 官方标准Python开发包和支持环境,同时也是Python的官方网站: * http://www.activestate ...
- c#异步等待
1:一直等待 2方法 现实等待 3:方法 带返回值得 begin -endinvoke 4: func 带返回值
- (轉)JSON.stringify 语法实例讲解
作用:这个函数的作用主要是为了系列化对象的. 可能有些人对系列化这个词过敏,我的理解很简单.就是说把原来是对象的类型转换成字符串类型(或者更确切的说是json类型的).就这么简单.打个比方说,你有一个 ...
- (转)Oracle 使用 DBLINK详解
DBLINK详解 1.创建dblink语法: CREATE [PUBLIC] DATABASE LINK link CONNECT TO username IDENTIFIED BY password ...
- PAT 1031 查验身份证(15)(C++&Python)
1031 查验身份证(15)(15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8, ...
- Loadrunner使用键盘快捷键
---------Loadrunner使用键盘快捷键------------ alt+f8 比较当前快照(仅限于 Web Vuser) alt+ins 新建步骤 ctrl+a 全选 ctrl+c 复制 ...
- linux工具介绍
http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/index.html 工具参考篇 1. gdb 调试利器 2. ldd 查看程序依赖库 3 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- 小话C源码移植
我们知道国外很多程序员工作在linux / unix 环境下,所以有很多优秀的c/c++语言代码不能直接在windows平台进行编译. 很多时候我们只能使用msys, cmake等工具进行模拟环境编译 ...
- nginx域名转发 负载均衡 反向代理
公司有三台机器在机房,因为IP不够用,肯定要分出来,所以要建立单IP 多域名的反向代理, 就是当请求www.abc.com 跳转到本机, 请求www.bbc.com 跳转到192.168.0.35 机 ...