#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#define ll long long using namespace std;
const int N = 1e5+; int dp[*][][];
int maze[][]; int dfs(int sum,int a,int b)
{
if(dp[sum][a][b] != -)
return dp[sum][a][b];
if(sum == && a == && b == )
return dp[sum][a][b] = maze[][];
dp[sum][a][b] = ;
if(a == b)
{
if(sum - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a,b) + maze[a][sum-a]);
if(sum - >= && a - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a-,b)+ maze[a][sum-a]);
if(sum - >= && b - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a,b-) + maze[a][sum-a]);
if(sum - >= && a - >= && b - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a-,b-) + maze[a][sum-a]);
}
else
{
if(sum - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a,b) + maze[a][sum-a]+maze[b][sum-b]);
if(sum - >= && a - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a-,b)+ maze[a][sum-a]+maze[b][sum-b]);
if(sum - >= && b - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a,b-) + maze[a][sum-a]+maze[b][sum-b]);
if(sum - >= && a - >= && b - >= )
dp[sum][a][b] = max(dp[sum][a][b],dfs(sum-,a-,b-) + maze[a][sum-a]+maze[b][sum-b]);
}
return dp[sum][a][b];
} void solve()
{
int m,n;
scanf("%d %d",&m,&n);
memset(dp,-,sizeof(dp));
memset(maze,,sizeof(maze));
for(int i = ; i < m; i++)
for(int j = ; j < n; j++)
scanf("%d",&maze[i][j]); int ans = dfs(n+m-,m-,m-); printf("%d\n",ans);
} int main(void)
{
int t,cnt = ;
scanf("%d",&t); while(t--)
{
printf("Case %d: ",++cnt);
solve();
}
return ;
}

light oj 1071 dp(吃金币升级版)的更多相关文章

  1. light oj 1231 dp 多重背包

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...

  2. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  3. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  4. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  5. 4829 [DP]数字三角形升级版

    4829 [DP]数字三角形升级版  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 从数字三角形的顶部(如图, ...

  6. 【Unity3D】模仿制作“神庙逃亡”吃金币后金币飞出屏幕效果

    [前言] 玩过“神庙逃亡”的应该都知道,这款游戏不论从游戏流畅度.人物动画.场景的管理都很棒. 自己也做了一款简单的跑酷游戏,实现了简单的吃金币效果,但是发现不好看,于是就想模仿“神庙逃亡”中的这个效 ...

  7. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  8. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  9. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

随机推荐

  1. 求一个n!中尾数有多少个零

    题目描述: 输入一个正整数n,求n!(即阶乘)末尾有多少个0? 比如: n = 10; n! = 3628800,所以答案为2 输入描述: 输入为一行,n(1 ≤ n ≤ 1000) 输出描述: 输出 ...

  2. Django之跨表查询——正反向查询(ForeignKey)

    1.正向查询和反向查询: 外键的查询操作: 正向查询: # 正向查询 # 基于对象,跨表查询 book_obj = models.Book.objects.all().first() ret = bo ...

  3. 2018-9-20-在-Windows-下那些好用的调试软件

    title author date CreateTime categories 在 Windows 下那些好用的调试软件 lindexi 2018-9-20 17:37:1 +0800 2018-09 ...

  4. jvisualvm 工具使用【转】

    VisualVM 是Netbeans的profile子项目,已在JDK6.0 update 7 中自带(java启动时不需要特定参数,监控工具在bin/jvisualvm.exe). https:// ...

  5. 修改Apache的默认站点目录的方法,需要的朋友可以参考下

    由于博客系统崩了,所以要考虑重新建立博客系统,首先遇到的一个问题就是原来的博客系统是安装一个独立的磁盘上面的(http://m.0834jl.com)不是安装在系统盘上面的,然而一般在linux下面安 ...

  6. 廖雪峰Java11多线程编程-3高级concurrent包-7Future

    JDK提供了ExecutorService接口表示线程池,可以通过submit提交一个任务. ExecutorService executor = Executors.newFixedThreadPo ...

  7. 【转载】TCP演进简述

    TCP演进简述 http://www.cnblogs.com/fll/ 一.互联网概述 TCP,即传输控制协议,是目前网络上使用的最多的传输协议,我们知道,整个互联网的体系结构是以IP协议提供的无连接 ...

  8. RSA算法的基本原理

    记得在我上初一的时候做过这么一道数学竞赛题,就是求7的222次方的个位数字.当时教材上介绍的解题方法是将222分解成4*55+2,然后算出7的2次方个个位数字即为要算的数值.当时年幼无知的我根本不了解 ...

  9. P++ 1.0.5

    #include<bits/stdc++.h> #define begin { #define end } #define while while( #define if if( #def ...

  10. intrinsicContentSize和Content Hugging Priority

    Mgen | 首页 | | 发新文章 | 联系 | 订阅  | 管理 iOS: 在代码中使用Autolayout (2) - intrinsicContentSize和Content Hugging ...