[HDOJ1087]Super Jumping! Jumping! Jumping!
2015-09-04 01:55
357 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
就是求最长上升子序列,但是结果求的是该序列的和,转移方程: dp[i] = max(dp[i], dp[j]+a[i])
就是求最长上升子序列,但是结果求的是该序列的和,转移方程: dp[i] = max(dp[i], dp[j]+a[i])
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <queue> #include <map> #include <set> #include <stack> #include <list> #include <vector> using namespace std; inline int max(int a, int b) { return a > b ? a : b; } const int maxn = 1010; int n; int a[maxn]; int dp[maxn]; int ans; int main() { // freopen("in", "r", stdin); while(~scanf("%d", &n) && n) { ans = 0; for(int i = 0; i < n; i++) { scanf("%d", &a[i]); } for(int i = 0; i < n; i++) { dp[i] = a[i]; for(int j = 0; j < i; j++) { if(a[j] < a[i]) { dp[i] = max(dp[i], dp[j] + a[i]); } } ans = max(ans, dp[i]); } printf("%d\n", ans); } }
相关文章推荐
- POJ1066Treasure Hunt【判断直线相交】
- POJ 1056 解题报告
- clearcase 中一些概念和操作
- clearcase 中一些概念和操作
- C/C++ Resources
- C/C++ Resources
- Android test---robotium----简单例子
- [LeetCode#241]Different Ways to Add Parentheses
- Linux I/O 重定向详解及应用实例
- c/c++ 直接使用动态库 dlopen
- Linux I/O 重定向详解及应用实例
- c/c++ 直接使用动态库 dlopen
- c++ __declspec关键字详细用法
- c++ __declspec关键字详细用法
- c++ try throw catch
- c++ try throw catch
- Sudoku Solver
- 第一次写博客...
- c friend -- 友元
- c++ virturn function -- 虚函数