UVa 11790 - Murcia's Skyline

称号:给你一个行长度的建设和高度,我们祈求最长的和下降的高度。

分析:dp,最大上升子。

说明:具有长度,不能直接优化队列单调。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int h[2000],w[2000],u[2000],l[2000];

int main()
{
	int T,n;
	while (~scanf("%d",&T))
	for (int t = 1 ; t <= T ; ++ t) {
		scanf("%d",&n);
		for (int i = 0 ; i < n ; ++ i)
			scanf("%d",&h[i]);
		for (int i = 0 ; i < n ; ++ i)
			scanf("%d",&w[i]);

		int in = 0,de = 0;
		for (int i = 0 ; i < n ; ++ i) {
			u[i] = l[i] = w[i];
			for (int j = 0 ; j < i ; ++ j) {
				if (h[j] < h[i] && u[i] < u[j]+w[i])
					u[i] = u[j]+w[i];
				if (h[j] > h[i] && l[i] < l[j]+w[i])
					l[i] = l[j]+w[i];
			}
			if (in < u[i]) in = u[i];
			if (de < l[i]) de = l[i];
		}
		if (in >= de)
			printf("Case %d. Increasing (%d). Decreasing (%d).\n",t,in,de);
		else printf("Case %d. Decreasing (%d). Increasing (%d).\n",t,de,in);
	}
	return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVa 11790 - Murcia's Skyline

时间: 2024-07-29 14:14:18

UVa 11790 - Murcia&#39;s Skyline的相关文章

UVa 11790 - Murcia&#39;s Skyline

题目:给你一排建筑的长度和高度,求最长的上横高度和下降高度. 分析:dp,最大上升子序列. 说明:有长度,不能直接用单调队列优化. #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int h[2000],w[2000],u[2000],l[2000]; int main() { int T,n; while (~scanf("%d",&

UVA 11825 - Hackers&amp;#39; Crackdown 状态压缩 dp 枚举子集

UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:11825 - Hackers' Crackdown 题意: 有一个由编号0~n-1的n台计算机组成的网络,一共同拥有n种服务,每台计算机上都执行着所有服务,对于每台计算机,你能够选择停止一项服务,这个行为会导致与这台计算机和与他相连的其它计算机上的这项服务都停止(原来已经停止的继续保持停止状态). 求最多能使多少个服务瘫痪(即没有不论什么一台计算机在执行这项服务). 分析: 题目说白了.就

【UVA】434-Matty&amp;#39;s Blocks

一道非常easy想复杂的题,给出主视图和右视图,计算最少能用几个正方体组成相应的视图,以及最多还能加几块正方体. 求最多加入事实上就是求出最多的正方体数减去最少的,主要就是最少的不好求. 一開始各种模拟就是不正确,之后发现,仅仅须要统计两个视图的高度个数就能够了(简直了) 14390495 434 Matty's Blocks Accepted C++ 0.016 2014-10-21 11:35:11 #include<cstdio> #include<cstring> #inc

uva 11825 Hackers&amp;#39; Crackdown (状压dp,子集枚举)

题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪(没有计算机有该项服务). 思路:(见大白70页,我的方程与大白不同) 把n个集合P1.P2.Pn分成尽量多的组,使得每组中全部集合的并集等于全集,这里的集合Pi是计算机i及其相邻计算机的集合,用cover[i]表示若干Pi的集合S中全部集合的并集,dp[s]表示子集s最多能够分成多少组,则 假设co

UVA 11774 - Doom&amp;#39;s Day(规律)

UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,例如以下: We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cel

UVA - 434 Matty&amp;#39;s Blocks

题意:给你正视和側视图,求最多多少个,最少多少个 思路:贪心的思想.求最少的时候:由于能够想象着移动,尽量让两个视图的重叠.所以我们统计每一个视图不同高度的个数.然后计算.至于的话.就是每次拿正视图的高度去匹配側视求最大 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int MAXN = 1000

UVA 10026 Shoemaker&amp;#39;s Problem

Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each ith job, it is known the integer Ti (1<=Ti<=1000), the time in days it takes the shoemaker to finish the jo

uva 10831 - Gerg&amp;#39;s Cake(勒让德符号)

题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap?12≡1%p #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll pow_mod (ll a, ll n, ll mod) { ll ans = 1; while

uva 11178 Morley&amp;#39;s Theorem(计算几何-点和直线)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below