题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686

  经典的多进程DP,比较简单。f[x1][y1][x2][y2]表示起点到点(x1,y1)和(x2,y2)的最优值,然后分层转移就可以了,每一层为斜向右的线。。

 //STATUS:C++_AC_46MS_6172KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int d[][]={{-,,-,},{-,,,-},{,-,,-},{,-,-,}};
int ma[N][N],f[N][N][N][N],xy[*N][];
int n; int main(){
// freopen("in.txt","r",stdin);
int i,j,q,p,k,x0,y0,w,x1,y1,x2,y2,nx1,ny1,nx2,ny2,up;
while(~scanf("%d",&n))
{
for(i=;i<n;i++){
for(j=;j<n;j++)
scanf("%d",&ma[i][j]);
}
mem(f,);
f[][][][]=ma[][]+ma[][]+ma[][];
up=(n-)<<|;x0=,y0=;w=;
for(i=;i<up-;i++){
i<=up/?(x0++,w++):(y0++,w--);
for(j=;j<w;j++){
xy[j][]=x0-j;
xy[j][]=y0+j;
}
for(q=;q<w;q++){
for(p=q+;p<w;p++){
x1=xy[q][],y1=xy[q][];
x2=xy[p][],y2=xy[p][];
for(k=;k<;k++){
nx1=x1+d[k][],ny1=y1+d[k][];
nx2=x2+d[k][],ny2=y2+d[k][];
if(nx1==nx2 && ny1==ny2)continue;
if(nx1<||ny1< || nx2<||ny2<)continue;
f[x1][y1][x2][y2]=Max(f[x1][y1][x2][y2],f[nx1][ny1][nx2][ny2]+ma[x1][y1]+ma[x2][y2]);
}
}
}
} n--;
printf("%d\n",f[n][n-][n-][n]+ma[n][n]); }
return ;
}

HDU-2686 Matrix 多进程DP的更多相关文章

  1. HDU 2686 Matrix 多线程dp

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

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

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

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

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

  4. hdu 5569 matrix(简单dp)

    Problem Description Given a matrix with n rows and m columns ( n+m ,) and you want to go to the numb ...

  5. hdu 2686(状压dp)

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

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

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

  7. HDU 2686 Matrix(最大费用最大流+拆点)

    题目链接:pid=2686">http://acm.hdu.edu.cn/showproblem.php?pid=2686 和POJ3422一样 删掉K把汇点与源点的容量改为2(由于有 ...

  8. POJ 2135 Farm Tour &amp;&amp; HDU 2686 Matrix &amp;&amp; HDU 3376 Matrix Again 费用流求来回最短路

    累了就要写题解,近期总是被虐到没脾气. 来回最短路问题貌似也能够用DP来搞.只是拿费用流还是非常方便的. 能够转化成求满流为2 的最小花费.一般做法为拆点,对于 i 拆为2*i 和 2*i+1.然后连 ...

  9. HDU 2686 Matrix(最大费用流)

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

随机推荐

  1. uva 10986

    ford 超时  使用优先队列的Dijkstra 算法 //#include <cstdio> //#include <cstring> //#include <algo ...

  2. Flume学习——Flume的架构

    Flume有三个组件:Source.Channel 和 Sink.在源码中对应同名的三个接口. When a Flume source receives an event, it stores it ...

  3. 【NGUI】屏幕自适应(不用UIStretch,用UIRoot)---------------good

    原地址:http://blog.csdn.net/lzhq1982/article/details/18814023 这篇文章是转载的,之前用UIStretch做屏幕自适应,但一直有两个硬伤让我难受, ...

  4. 1058-Tom and Jerry

    描述 Tom和Jerry在10*10的方格中: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*...... ...

  5. Android进程守护

    http://blog.csdn.net/t12x3456/article/details/8982198 http://blog.csdn.net/ljx19900116/article/detai ...

  6. Jquery-DataTable 使用介绍

    http://dt.thxopen.com/example/server_side/simple.html

  7. mysql-5.7.10-winx64 安装时遇到的问题

    1.修改密码# /etc/init.d/mysqld stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &am ...

  8. SQL Server中的分页

    sqlserver2000时的分页思路 .分页查询时,首先将数据排序 select * from MyStudent order by fid desc .取第一页数据 * from MyStuden ...

  9. Yii cookie操作

    设置cookie: $cookie = new CHttpCookie('mycookie','this is my cookie'); $cookie->expire = time()+60* ...

  10. 有关PHP 10条有用的建议

    1.使用ip2long() 和long2ip()函数来把IP地址转化成整型存储到数据库里. 这种方法把存储空间降到了接近四分之一(char(15)的15个字节对整形的4个字节),计算一个特定的地址是不 ...