题目链接

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. git个人使用总结(界面版)

    最近开始使用GIT来管理测试文档,从0到1开始使用git 1.首先,使用网页登录GIT后,创建项目 2.创建项目后,需要配置一下访问者权限 3.然后在网页版GIT复制地址,git clone到 本地 ...

  2. ASP.NET CORE RAZOR :将文件上传至 ASP.NET Core 中的 Razor 页面

    本部分演示使用 Razor 页面上传文件. 本教程中的 Razor 页面 Movie 示例应用使用简单的模型绑定上传文件,非常适合上传小型文件. 有关流式传输大文件的信息,请参阅通过流式传输上传大文件 ...

  3. Android布局中 android:layout_gravity="bottom"为何不起作用?

    在android布局时我们有时会需要将位于LinearLayout布局中的控件放在布局底部,或者是同时想将几个控件底部对齐,此时我们自然会想到使用 android:layout_gravity=&qu ...

  4. RAII手法封装相互排斥锁

    CriticalSectionWrapper是一个接口类 class CriticalSectionWrapper { public: // Factory method, constructor d ...

  5. nginx实现某个页面http访问,其余全部跳转到https

    全站https实现某个页面可以http访问,其余全部跳转到https,注意下面的location,如果不加root 配置 找不到这个文件的server { listen ; server_name w ...

  6. [译]GLUT教程 - 初始化

    Lighthouse3d.com >> GLUT Tutorial >> Basics >> Initialization 这一节开始从main函数入手.第一步是线 ...

  7. UVA 10131题解

    第一次写动态规划的代码,整了一天,终于AC. 题目: Question 1: Is Bigger Smarter? The Problem Some people think that the big ...

  8. php7.0 出现 curl_setopt(): Disabling safe uploads is no longer supported in 报错!

    项目换成php7.0,进行了测试,使用curl时,出现: curl_setopt(): Disabling safe uploads is no longer supported in xxx.定位到 ...

  9. VSCode 运行go test显示打印日志

    在VSCode中运行go test,在代码中写的 fmt.Printf("TestB \n") 这些语句均不打印,只显示最终的结果 PASS ok github.com/B .03 ...

  10. qb64手记(2)

    传值与传引用 PRINT mymax(12, 111) x1 = 55x2 = 66myswapPRINT x1 FUNCTION mymax (x, y)IF x > y THEN    my ...