题目链接

https://www.nowcoder.com/acm/contest/85/G

思路

按照题解上的方式 存取数据

然后DP一下 就可以了

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6; const int INF = 0x3f3f3f3f;
const int maxn = 3e3 + 5;
const int MOD = 1e9 + 7; int Map[maxn][maxn], Cur[maxn], dp[maxn][maxn]; int main()
{
int n;
scanf("%d", &n);
memset(Map, 0xc0, sizeof(Map));
memset(Cur, 0, sizeof(Cur));
memset(dp, 0, sizeof(dp));
int vis = 1 + (4 * (n - 1));
int cur = 2 * n - 1;
int i, j;
for (i = 0; i < n; i++)
Cur[i] = i + 1;
int opt[2];
opt[i % 2] = n - 1;
opt[!(i % 2)] = n;
int flag = i % 2;;
for ( ; i < (vis - n); i++, flag = !flag)
Cur[i] = opt[flag];
for (j = n ; i < vis; i++, j--)
Cur[i] = j;
vector <int> v[vis];
int temp;
for (i = 0; i < vis; i++)
{
for (j = 0; j < Cur[i]; j++)
{
scanf("%d", &temp);
v[i].push_back(temp);
}
}
int len = cur/2 + 1;
flag = 0;
for (i = 0, j = n; i < len; i++, j++)
{
for (int l = 0, k = flag; l < j; l++, k++)
{
Map[i][l] = v[k][v[k].size() - 1];
v[k].pop_back();
if (v[k].size() == 0)
flag++;
}
}
for (j -= 2; i < cur; i++, j--)
{
for (int l = (cur - j), k = flag; l < cur; l++, k++)
{
Map[i][l] = v[k][v[k].size() - 1];
v[k].pop_back();
if (v[k].size() == 0)
flag++;
}
}
dp[0][0] = Map[0][0];
for (i = 1; i < cur; i++)
{
dp[0][i] = dp[0][i - 1] + Map[0][i];
dp[i][0] = dp[i - 1][0] + Map[i][0];
}
for (i = 1; i < cur; i++)
{
for (j = 1; j < cur; j++)
dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + Map[i][j];
}
cout << dp[cur - 1][cur - 1] << endl;
}

牛客小白月赛1 G あなたの蛙は旅⽴っています【DP】的更多相关文章

  1. 牛客小白月赛1 G あなたの蛙は旅⽴っています【图存储】【DP】

    题目链接:https://www.nowcoder.com/acm/contest/85/G 思路: DP 空间可以优化成一维的, 用一维数组的 0 号单元保存左斜对角的值即可. 存图这里真不好理解 ...

  2. 牛客小白月赛2 G 文 【模拟】

    链接:https://www.nowcoder.com/acm/contest/86/G来源:牛客网 题目描述 Sεlιнα(Selina) 开始了新一轮的男友海选.她要求她的男友要德智体美劳样样都全 ...

  3. 牛客网 牛客小白月赛1 I.あなたの蛙が帰っています-卡特兰数,组合数阶乘逆元快速幂

    I.あなたの蛙が帰っています   链接:https://www.nowcoder.com/acm/contest/85/I来源:牛客网     这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...

  4. 牛客小白月赛6 G 指纹锁 set的自动排序 模板

    链接:https://www.nowcoder.com/acm/contest/136/G来源:牛客网 题目描述     HA实验有一套非常严密的安全保障体系,在HA实验基地的大门,有一个指纹锁.   ...

  5. 牛客小白月赛1 I あなたの蛙が帰っています 【卡特兰数】

    链接:https://www.nowcoder.com/acm/contest/85/I题目描述 あなたの蛙が帰っています!  蛙蛙完成了一趟旅行,回家啦!但它还是没有去它心中非常想去的几个地方.总共 ...

  6. 牛客小白月赛5 G 异或(xor) 【找规律】

    题目链接: https://www.nowcoder.com/acm/contest/135/g 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apojacs ...

  7. 牛客网 牛客小白月赛2 G.文

    G.文 链接:https://www.nowcoder.com/acm/contest/86/G 这个题wa了一发,有点智障,浮点数,式子里面要*1.0,忘了,然后wa了,改了就过了(脑子有坑) 代码 ...

  8. 牛客小白月赛14 -G (筛法)

    题目链接:https://ac.nowcoder.com/acm/contest/879/G 题意:给定A1和A数组公式: 以及B数组: 求 思路:利用筛法更新b数组,最后求异或和即可. AC代码: ...

  9. 牛客小白月赛13 G(双向搜索)

    AC通道 两边同步搜,一步里面A走一次B走两次,遇到对方走过的地方就得到了答案. #include <bits/stdc++.h> using namespace std; const i ...

随机推荐

  1. OSGI中的service依赖关系管理

    众所周知.对于高动态高可扩展的应用,OSGI是一个很好的平台.可是.也因此添加了复杂性.开发中对service的依赖变得复杂. 这也是service的关系管理成为OSGI中一个很重要的部分,我们来看看 ...

  2. 基于JWT的Token开发案例

    代码地址如下:http://www.demodashi.com/demo/12531.html 0.准备工作 0-1运行环境 jdk1.8 maven 一个能支持以上两者的代码编辑器,作者使用的是ID ...

  3. svn上传代码时出现:Authorization failed

    出现该问题基本都是三个配置文件的问题,下面把这个文件列出来 svnserve.conf:[general]anon-access = readauth-access = writepassword-d ...

  4. org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 启动hibernate测试案例时报错如下: 2.解决方案: 2.1 第一次解决:MySQL驱动版本太高.使用的hibernate版本为5 ...

  5. Google 商店

    Google 商店地址:https://store.google.com/

  6. hdu 3367 Pseudoforest(并查集)

    题意:有一种叫作Pseudoforest的结构,表示在无向图上,每一个块中选取至多包含一个环的边的集合,又称“伪森林”.问这个集合中的所有边权之和最大是多少? 分析:如果没有环,那么构造的就是最大生成 ...

  7. iOS 字符属性NSAttributedString描述【转载】

    /* 字符属性 字符属性可以应用于 attributed string 的文本中. NSString *const NSFontAttributeName;(字体) NSString *const N ...

  8. listView的异步加载数据

    1 public class MainActivity extends Activity { 2 3 private ListView listView; 4 private ArrayList< ...

  9. iOS8的autolayout和size class

    前一阵子看到几篇不错的布局教程,Mark下. 初探iOS8中的size class 自适应布局(Adaptive Layout)教程1 自适应布局(Adaptive Layout)教程2 为iPhon ...

  10. struts2中配置文件加载的顺序是什么?

    struts2的StrutsPrepareAndExecuteFilter拦截器中对Dispatcher进行了初始化 在Dispatcher类的init方法中定义了配置文件的加载顺序(下面是源码) p ...