DP UVALive 6506 Padovan Sequence
2015-06-21 21:37
429 查看
题目传送门
/* 题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大 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 + 10; const int INF = 0x3f3f3f3f; int a[2][MAXN]; int dp[2][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, 0, sizeof (dp)); for (int i=0; i<=1; ++i) { for (int j=1; j<=n; ++j) { scanf ("%d", &a[i][j]); } } dp[0][1] = a[0][1]; dp[1][1] = a[1][1]; int ans = max (dp[0][1], dp[1][1]); for (int j=2; j<=n; ++j) { for (int i=0; i<=1; ++i) { dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[i][j]); if (j > 2) { dp[i][j] = max (dp[i][j], dp[i][j-2] + a[i][j]); dp[i][j] = max (dp[i][j], dp[1-i][j-2] + a[i][j]); } ans = max (ans, dp[i][j]); } } printf ("%d\n", ans); } return 0; }
相关文章推荐
- 找规律 UVALive 6506 Padovan Sequence
- UISlider
- .toString和String.valueOf()
- String、StringBuffer、StringBuilder三者的区别
- 文档型信息交互设计及相关技术实现
- 报错:this class is not key value coding-compliant for the key tableview
- UIView frame, bounds and center
- FrameLayou和UI的布局优化(merge、include、ViewStub)
- hdu 5273 Dylans loves sequence
- java.util.Queue用法
- GitHub 之 pull request 流程简介
- [Schema] I have updated my XML Schema for my service but SoapUI still generates/validates according to the old schema.
- iOS UILabel显示HTML文本
- iOS 在UILabel显示不同的字体和颜色
- 多线程 调用多线程的方法 Runtime与ProcessBuilder
- 安卓TV开发(五) 移动智能终端UI之实现主流TV焦点可控UI
- 安卓TV开发(五) 移动智能终端UI之实现主流TV焦点可控UI
- Canal AdminGuide canal信息介绍
- Uva - 11572 - Unique Snowflakes
- Error:No suitable device found: no device found for connection "System eth0"