HDU 1087

  题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值。(其实就是求最大上升(可不连续)子序列和)

  解题思路:可以定义状态dp[i]表示以a[i]为结尾的上升子序列的和的最大值,那么便可以得到状态转移方程

       dp[i] = max(dp[i], dp[j]+a[i]), 其中a[j]<a[i]且j<i;  另外每个dp[i]可以先初始化为a[i]

       理解:以a[i]为结尾的上升子序列可以由前面比a[i]小的某个序列加上a[i]来取得,故此有dp[j]+a[i], j < i, a[j] < a[i]三个条件

          若是前面没有比a[i]小的序列,那么dp[i]为a[i]本身,故此有dp[i]全初始化为a[i]。

          最后获取dp[i]数组中的最大值就是最终结果了。

/* HDU 1087 Super Jumping! Jumping! Jumping! --- dp */
#include <cstdio>
#include <cstring> int a[];
int dp[]; inline int MAX(int a, int b){
return a > b ? a : b;
} int main()
{
#ifdef _LOCAL
freopen("D:input.txt", "r", stdin);
#endif int n; while (scanf("%d", &n) == && n){ for (int i = ; i <= n; ++i){
scanf("%d", a + i); //获取n个数
dp[i] = a[i]; //dp[i]的初始化
}//for(i) //dp[i] = max(dp[i], dp[j]+a[i]), 其中a[j] < a[i]
int maxnum = dp[]; //max保存最终结果
for (int i = ; i <= n; ++i){
for (int j = ; j <= i; ++j){
if (a[j] < a[i]){
dp[i] = MAX(dp[i], dp[j] + a[i]);
if (dp[i] > maxnum){
maxnum = dp[i];
}
}
}//for(j)
}//for(i)
printf("%d\n", maxnum);
} return ;
}

HDU 1087 Super Jumping! Jumping! Jumping的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...

  2. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...

  3. HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  4. hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...

  5. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  6. hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. HDU 1087 Super Jumping! Jumping! Jumping! (DP)

    C - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  9. HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)

    Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...

随机推荐

  1. Rhel6-keepalived+lvs配置文档

    系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.119 server19.example.com 192.168.12 ...

  2. Linux Program

    vhost : web.myftp.com storage.myftp.com ...... not vhost : storage.myftp.com eg : top eg : htop eg : ...

  3. 访问FLASH设备-W25X16

    /************************************* *文件名称:w25x16_spi.c * *功能描述:访问和写入数据到闪存w25x16 * *建立日期:2016-03-1 ...

  4. C# ClickOnce deployment for Windows Services ClickOnce 部署windows service

    A simple solution that I use is to merely stop the service and x-copy the files from my bin folder i ...

  5. poj2631 树的直径 + bfs

    //Accepted 492 KB 0 ms //树的直径 bfs #include <cstdio> #include <cstring> #include <iost ...

  6. hdu4597 区间dp

    //Accepted 1784 KB 78 ms //区间dp //dp[l1][r1][l2][r2] 表示a数列从l1到r1,b数列从l2到r2能得到的最大分值 // #include <c ...

  7. Ajax的post方法,模拟 从后台读取数据小demo

    $(document).ready(function() { //定义一个函数 function timer() { $.post("1.json", function(data, ...

  8. (转) Tomcat部署Web应用方法总结

    原文:http://blog.csdn.net/yangxueyong/article/details/6130065 Tomcat部署Web应用方法总结 分类: Java web2011-01-11 ...

  9. hdu 2043

    Ps:自己写了以后又去看了下苏哥的....改进版的....学到东西,直接套用了. 代码: #include "stdio.h"#include "string.h&quo ...

  10. 自定义UIAlertView

    You can change accessoryView to any own customContentView in a standard alert view in iOS7 [alertVie ...