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 ...
随机推荐
- POJ 1284 Primitive Roots (求原根个数)
Primitive Roots 题目链接:id=1284">http://poj.org/problem?id=1284 利用定理:素数 P 的原根的个数为euler(p - 1) t ...
- 实例 tar备份以日期命名
tar备份以日期命名****************************************************************************************#v ...
- sql跟踪及tkprof使用
简述 在oracle数据库中,awr是关于数据库系统总体的负载情况和运行情况的报告.而当系统负载都显示正常,而client运行某些动作响应非常慢,或者某些终端连接的会话运行缓慢或异常时,就须要用到会话 ...
- DB 查询分析器 6.03 ,遨游于不论什么Windows操作系统之上的最棒的数据库client工具
DB 查询分析器 6.03 ,遨游于不论什么Windows操作系统之上的最棒的数据库client工具 中国本土程序猿马根峰(CSDN专訪马根峰:海量数据处理与分析大师的中国本土程序猿 .03版本 ...
- shell操作Hbase
status:查询集群的一些状态 hbase(main):002:0> status1 active master, 0 backup masters, 1 servers, 0 dead, 3 ...
- A Simple Example About Privileged Methods in JavaScript
Douglas Crockford classified the "class methods" in JavaScript into three types: private, ...
- Part1-Redefining your data-access strategy 重新定义你的数据访问策略
欢迎来到Entity Framework 4 In Action,EF是微软3.5 SP1推出的ORM工具,现在已经更新到4.0版本(...)本书能确保你in a robust and model- ...
- (转)SQL中使用or影响性能的解决办法
原文地址:https://www.cnblogs.com/xuxiaona/p/4962727.html 近期做了一个存储过程,执行时发现非常的慢,竟然需要6.7秒! 经排查,发现时间主要都耗在了其中 ...
- html页面内锚点定位及跳转方法总结
1.最简单的方法是锚点用<a>标签,在href属性中写入DIV的id.如下: <!DOCTYPE html><html><head><style& ...
- I.MX6 mkuserimg.sh 使用
/*********************************************************************** * I.MX6 mkuserimg.sh 使用 * 说 ...