DP UVALive 6506 Padovan Sequence
/*
题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大
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的更多相关文章
- 找规律 UVALive 6506 Padovan Sequence
题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...
- 状压DP uvalive 6560
// 状压DP uvalive 6560 // 题意:相邻格子之间可以合并,合并后的格子的值是之前两个格子的乘积,没有合并的为0,求最大价值 // 思路: // dp[i][j]:第i行j状态下的值 ...
- 区间DP POJ 1141 Brackets Sequence
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29520 Accepted: 840 ...
- [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 ...
- AC自动机基础知识讲解
AC自动机 转载自:小白 还可参考:飘过的小牛 1.KMP算法: a. 传统字符串的匹配和KMP: 对于字符串S = ”abcabcabdabba”,T = ”abcabd”,如果用T去匹配S下划线部 ...
- Todolist
UValive 6041(KD tree) UValive 6042(DP) UValive 6044(图论)
- Arithmetic Slices II - Subsequence LT446
446. Arithmetic Slices II - Subsequence Hard A sequence of numbers is called arithmetic if it consis ...
- leetcode array解题思路
Array *532. K-diff Pairs in an Array 方案一:暴力搜索, N平方的时间复杂度,空间复杂度N 数组长度为10000,使用O(N平方)的解法担心TLE,不建议使用,尽管 ...
- USB 3.0规范中译本 第8章 协议层
本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 协议层管理设备及其主机之间端到端的数据流.这一层建立在链路层提供对某些类型的包的保证传输(guarantee ...
随机推荐
- 【stl学习笔记】vector
vector是定义于namespace std内的template: namespace std { template<class T, class Allocator = allocator& ...
- linux定时访问url
cd /root touch test.sh #创建文件 vim test.sh #!/bin/sh URL="url地址" curl $URL 保存 退出 #修改文件属性,使其可 ...
- 性能监控 -- 中间件性能监控【Weblogic控制台】
通过WebLogic管理控制台可以实时获取各性能指标,通过控制台,可以对weblogic的性能及运行状况,发布的应用.资源等进行监视 1. 进入Weblogic管理控制台,单击服务器,选择一台需监控的 ...
- OO模式-Composite
组合模式也叫做"部分-总体"模式,这样事实上定义也就非常明显了,正好和数据结构的知识相相应.把对象组合成树形结构以表示"部分-总体"的层次结构. 先看类图: w ...
- IPython与Jupyter notebook 安装与配置,插件扩展,主题,PDF输出
基于 python2.7.13 32-bit版本安装 1.安装pyreadline https://pypi.python.org/pypi/pyreadline 下载对应的32位版本 安装Micro ...
- url加密并计算时间
将URL地址参数进行加密传输提高网站安全性 加密算法,直接调用就好 function keyED($txt,$encrypt_key){ $encrypt_key = md5($encrypt_key ...
- angularjs学习之六(angularjs中directive指令的一般编程事件绑定 模板使用等)
angular js 中模板的使用.事件绑定以及指令与指令之间的交互 相应教学视频地址(需FQ):v=aG8VD0KvUw4">angularjs教学视频 <!doctype h ...
- MySQL 高可用架构在业务层面细化分析研究
相对于传统行业的相对服务时间9x9x6或者9x12x5,由于互联网电子商务以及互联网游戏的实时性,所以服务要求7*24小时,业务架构无论是应用还是数据库,都须要容灾互备.在mysql的体系中,最好通过 ...
- C++的cout高阶格式化操作
这篇文章主要讲解如何在C++中使用cout进行高级的格式化输出操作,包括数字的各种计数法(精度)输出,左或右对齐,大小写等等.通过本文,您可以完全脱离scanf/printf,仅使用cout来完成一切 ...
- HDU1698 Just a Hook —— 线段树 区间染色
题目链接:https://vjudge.net/problem/HDU-1698 In the game of DotA, Pudge’s meat hook is actually the most ...