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

水题,可是我却因为dp数组的初始化造成了多遍wa,这题就是求上升序列的最大和。

转移方程:

首先要对dp初始化。

if(w[i]>w[j]) dp[i]=dp[j]+w[i];i>j

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define inf 0x3f3f3f3f
using namespace std;
int n,w[],dp[];
int main()
{
int maxx;
while(scanf("%d",&n)!=EOF&&n!=)
{
memset(dp,,sizeof(dp));
for(int i=; i<n; i++)
{
scanf("%d",&w[i]);
dp[i]=w[i];//边界问题要好好考虑,输入3 5 3 4
}
dp[]=w[];
maxx=w[];
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
{
if(w[i]>w[j])
dp[i]=max(dp[i],dp[j]+w[i]);
}
maxx=max(maxx,dp[i]);
}
printf("%d\n",maxx);
}
return ;
}

HDU1087:Super Jumping! Jumping! Jumping!(简单dp)的更多相关文章

  1. HDu1087 Super Jumping! Jumping! Jumping!

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 分析:简单dp:dp[i] = max (dp[i], dp[j] + a[i]) 1 #inc ...

  2. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

  3. HDU 1087 简单dp,求递增子序列使和最大

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

  4. 4.15 每周作业 —— 简单DP

    免费馅饼 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

  5. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  6. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  7. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

  8. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  9. poj 1157 LITTLE SHOP_简单dp

    题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...

  10. hdu 2471 简单DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=(  dp[n-1][m],dp[n][m-1],d[i][k ...

随机推荐

  1. C++ 类的构造函数使用规则

    //类的构造函数使用规则 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Poi ...

  2. Hive三种不同的数据导出的方式

    转自:http://blog.chinaunix.net/uid-27177626-id-4653808.html Hive三种不同的数据导出的方式,根据导出的地方不一样,将这些方法分为三类:(1)导 ...

  3. Thinkphp新增字段无法插入到数据库问题

    Thinkphp框架开发过程中,因需求需要改动数据表,新增了几个字段. 调用 M(‘xxx’)->add($data) 插入值时,新增的字段数据总是插入不进去,每次都是默认的值,于是恍然—-缓存 ...

  4. Ubuntu16.04 Tomcat9的安装

    1. 从http://tomcat.apache.org/download-90.cgi 下载apache-tomcat-9.0.0.M11.tar.gz 2. 上传到Linux后移动到/opt/to ...

  5. loadruner11 socket脚本-10053错误

    背景: socket 10053异常:软件主动放弃一个连接,原因是超时或协议错误.如果LR客户端报10053异常,说明LR在执行套接字操作时,发生通信超时.网络中断或其它异常,主动将Socket连接断 ...

  6. [python]常用的几个包

    http://dev.mysql.com/doc/connector-python/en/connector-python-tutorial-cursorbuffered.html https://d ...

  7. Oracle自定义聚集函数

    今天工作中看见别人写的自定义聚集函数,所以一门心思的想搞懂,就在网上找资料了. 自定义聚集函数 自定义聚集函数接口简介 Oracle提供了很多预定义好的聚集函数,比如Max(), Sum(), AVG ...

  8. C#三种字符串拼接方法的效率对比

    C#字符串拼接的方法常用的有:StringBuilder.+.string.Format.List<string>.使用情况不同,效率不同. 1.+的方式 string sql = &qu ...

  9. gulp报错160

    gulp报错: 这种提示,说明端口被占用,并且要改端口号,首先,我需要把Apache服务器关掉, 然后在gulpfile.js里: 把8080的端口号加进去.就解决了

  10. Course Selection CodeChef - RIN

    All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russ ...