题目传送门

/*
题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大
DP:状态转移方程:dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[i][j], dp[i/1-i][j-2] + a[i][j]);
要从前面一个转态推过来啊,我比赛写反了,内功不够:(
*/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <cstdlib>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[][MAXN];
int dp[][MAXN]; int main(void) //UVALive 6506 Padovan Sequence
{
// freopen ("K.in", "r", stdin); int t; scanf ("%d", &t);
while (t--)
{
int n; scanf ("%d", &n);
memset (dp, , sizeof (dp)); for (int i=; i<=; ++i)
{
for (int j=; j<=n; ++j)
{
scanf ("%d", &a[i][j]);
}
} dp[][] = a[][]; dp[][] = a[][];
int ans = max (dp[][], dp[][]);
for (int j=; j<=n; ++j)
{
for (int i=; i<=; ++i)
{
dp[i][j] = max (dp[i][j], dp[-i][j-] + a[i][j]);
if (j > )
{
dp[i][j] = max (dp[i][j], dp[i][j-] + a[i][j]);
dp[i][j] = max (dp[i][j], dp[-i][j-] + a[i][j]);
}
ans = max (ans, dp[i][j]);
}
} printf ("%d\n", ans);
} return ;
}

DP UVALive 6506 Padovan Sequence的更多相关文章

  1. 找规律 UVALive 6506 Padovan Sequence

    题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...

  2. 状压DP uvalive 6560

    // 状压DP uvalive 6560 // 题意:相邻格子之间可以合并,合并后的格子的值是之前两个格子的乘积,没有合并的为0,求最大价值 // 思路: // dp[i][j]:第i行j状态下的值 ...

  3. 区间DP POJ 1141 Brackets Sequence

    Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29520   Accepted: 840 ...

  4. [POJ1180&POJ3709]Batch Scheduling&K-Anonymous Sequence 斜率优化DP

    POJ1180 Batch Scheduling Description There is a sequence of N jobs to be processed on one machine. T ...

  5. AC自动机基础知识讲解

    AC自动机 转载自:小白 还可参考:飘过的小牛 1.KMP算法: a. 传统字符串的匹配和KMP: 对于字符串S = ”abcabcabdabba”,T = ”abcabd”,如果用T去匹配S下划线部 ...

  6. Todolist

    UValive 6041(KD tree) UValive 6042(DP) UValive 6044(图论)

  7. Arithmetic Slices II - Subsequence LT446

    446. Arithmetic Slices II - Subsequence Hard A sequence of numbers is called arithmetic if it consis ...

  8. leetcode array解题思路

    Array *532. K-diff Pairs in an Array 方案一:暴力搜索, N平方的时间复杂度,空间复杂度N 数组长度为10000,使用O(N平方)的解法担心TLE,不建议使用,尽管 ...

  9. USB 3.0规范中译本 第8章 协议层

    本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 协议层管理设备及其主机之间端到端的数据流.这一层建立在链路层提供对某些类型的包的保证传输(guarantee ...

随机推荐

  1. C#编程语言及.NET 平台快速入门指南

    github: https://github.com/mfjiang e-mail: hamlet.jiang@live.com   ⼀.C#,CLR,IL,JIT概念 以及 .NET 家族 (⼀)基 ...

  2. C++设计模式之适配器模式(二)

    3.Socket网络通信的设计与实现------类适配器 除了对象适配器模式之外.适配器模式另一种形式.那就是类适配器模式,类适配器模式和对象适配器模式最大的差别在于适配器和适配者之间的关系不同,对象 ...

  3. hdu 4950 Monster(数学题,多校8)

    题目链接:pid=4950http://acm.hdu.edu.cn/showproblem.php?pid=4950">http://acm.hdu.edu.cn/showprobl ...

  4. 在XX公司工作第二天,维护已有代码

    根据<C++ More Exception>所述的规则: Rule #1: Never write using-directives in header files. Rule #2: N ...

  5. E. Dreamoon and Strings(Codeforces Round #272)

    E. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. MongoDB 自己定义函数

    定义 db.system.js.insert({ _id : "TestConcat", value : function TestConcat(s1, s2){ return s ...

  7. 分享:Mac与Phy组成原理的简单分析

    原文链接:http://blog.chinaunix.net/uid-20528014-id-3050217.html 1.General 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成. ...

  8. 在学习c++过程中,总结类的三个用户以及使用权限,感觉非常实用

    首先我们需要知道类的三个用户分别是:类的实现者,类的普通用户和类的继承者(派生类),接下来分别讲解这几种用户的区别. 1 .类的实现者:顾明思议,就是类的设计者,拥有最大的权限,可以访问类中任何权限的 ...

  9. 卸载ubuntu自带openJDK,更改成自己的JDK版本

    你已经成功把jdk1.6.0_03 安装到 /usr/java,并且配置好了系统环境变量 执行 # java -version 时就是 显示jdk1.4.3,是因为你的linux系统有默认的jdk;执 ...

  10. 打造字符界面的多媒体Linux系统

    0 环境与目标 硬件:ThinkPad R52笔记本一台. 目标:字符界面的Linux系统,同时可以看图片,听音乐,看视频,无线上网,重要的是可以听着音乐编程了! 注意:本文打造的系统主要是供一个工程 ...