Uva 11078 简单dp

题目链接:http://uva.onlinejudge.org/external/110/11078.pdf

a[i] - a[j] 的最大值。

这个题目马毅问了我,O(n^2)超时,记忆化一下当前最大值。

 1 #include <bits/stdc++.h>
 2
 3 using namespace std;
 4
 5 int A[100000],n;
 6
 7 int main()
 8 {
 9     int t;
10     cin>>t;
11     while(t--) {
12         cin>>n;
13         for(int i=0;i<n;i++) {
14             cin>>A[i];
15         }
16         int ans = -0x3f3f3f3f;
17         int maxai = A[0];
18         for(int i=1;i<n;i++) {
19             ans = max(ans,maxai-A[i]);
20             maxai = max(maxai,A[i]);
21         }
22
23         cout<<ans<<endl;
24     }
25     return 0;
26 }
时间: 2024-08-03 10:54:30

Uva 11078 简单dp的相关文章

UVA 111 简单DP 但是有坑

题目传送门:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18201 其实是一道不算难的DP,但是搞了好久,才发现原来是题目没读清楚,囧,原序列那里简直太坑了, 看了别人好多的都是用最长公共子序列,但是我用的是最长上升子序列来做,就是将原序列逐渐递增映射成递增的数列,这道题目的数据恰好符合这个条件 比如正确的序列为$$5 \ 6 \ 4  \ 1 \  3 \  2$$,我就可以将他一一映射成为 $$ID[5]\right

uva 10648(简单dp)

Recently one of my friend Tarik became a member of the food committee of an ACM regional competition. He has been given m distinguishable boxes, he has to put n types of chocolates in the boxes. The probability that one chocolate is placed in a certa

UVA - 11584 划分字符串的回文串子串; 简单dp

/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单dp 题目大意: 给一个字符串, 要求把它分割成若干个子串,使得每个子串都是回文串.问最少可以分割成多少个. 定义:dp[i]表示前0~i内的字符串划分成的最小回文串个数: dp[i] = min(dp[j]+1 | j+1~i是回文串); 先预处理flag[i][j]表示以i~j内的字符串为回文串

UVA 10453 Make Palindrome(区间简单DP)

题意:给出一个字符串A,求出需要至少插入多少个字符使得这个字符串变成回文串. 思路:设dp[i][j]为使区间[i, j]变成回文串所需要的最少字符个数. 1.A[i] == A[j的情况]那么dp[i][j] = min(dp[i][j], dp[i + 1][j -1]); 2.或者在第j个位置插入一个字符A[i], dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1); 3.或者在第i个位置插入一个字符A[j], dp[i][j] = min(dp[i][j

UVA 10003 区间DP

这个题目蛮有新意的,一度导致我没看透他是区间DP 给一个0-L长度的木板,然后给N个数,表示0-L之间的某个刻度,最后要用刀把每个刻度都切一下 使其断开,然后每次分裂的cost是分裂前的木板的长度.求整个分开之后的最小cost. 当时下意识就想到类似花瓶插花问题,即dp[i][j],表示第i个事物放在第j次动作来的最小代价,但是当我写起来发现很麻烦,我是以刻度点来表示的i,结果发现处理起来相当麻烦,因为实体实际是一块一块的小木板,以点作为转移变量 不仅要加诸多限制,而且加完后发现会互相矛盾,原因

uva 1543 - Telescope(dp+几何)

大数除法说的比较少或许不像加法减法那样简单,或许是用的不太多.到底怎么我也不知道. 反正你会了加法减法,乘法而不会除法,就像是,打开电脑而不玩游戏,心里难受. 我是从看到了大神博客后学习了一下. http://blog.csdn.net/hitwhylz/article/details/9700935 博客中讲的很详细 让人一看就懂,我很佩服这位同学.果断的关注了. 毕竟别人写的是别人的. 自己写的才是自己的 .于是我就捋了捋,模仿这写了一遍: 思想就是:用减法来代替除法,但是一次一次的减太慢,

[2016-03-19][UVA][11078][Open Credit System]

时间:2016-03-19 20:58:13 星期六 题目编号:[2016-03-19][UVA][11078][Open Credit System] 题目大意:求一个序列中 Ai - Aj的最大值(i < j) 分析:维护j前面最大的Ai ,更新ans即可 #include <cstdio> #include<algorithm> using namespace std; #define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x

POJ 3250 Bad Hair Day 简单DP 好题

Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a sp

uva 12723 概率dp

Dudu is a very starving possum. He currently stands in the first shelf of a fridge. This fridge iscomposed of N shelves, and each shelf has a number Qi (1 ≤ i ≤ N) of food. The top shelf, whereDudu is, is identified by the number 1, and the lowest is