The Twin Towers zoj2059 DP
The Twin Towers
Time Limit: 2 Seconds Memory Limit: 65536 KB
Twin towers we see you standing tall, though a building's lost our faith will never fall.
Twin towers the world hears your call, though you're gone it only strengthens our resolve.
We couldn't make it through this without you Lord, through hard times we come together more. ...
Twin Towers - A Song for America
In memory of the tragic events that unfolded on the morning of September 11, 2001, five-year-old Rosie decids to rebuild a tallest Twin Towers by using the crystals her brother has collected for years. Will she succeed in building the two towers of the same height?
Input
There are mutiple test cases.
One line forms a test case. The first integer N (N < 100) tells you the number of crystals her brother has collected. Then each of the next N integers describs the height of a certain crystal.
A negtive N indicats the end.
Note that all crytals are in cube shape. And the total height of crystals is smaller than 2000.
Output
If it is impossible, you would say "Sorry", otherwise tell her the height of the Twin Towers.
Sample Input
4 11 11 11 11
4 1 11 111 1111 
-1
Sample Output
22
Sorry
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define mod 1000000000
int a[],b[][];
int ma(int x,int y)
{
return x>y?x:y;
}
int main()
{
int n,i,j;
while(scanf("%d",&n))
{
if(n<)break;
int s=;
for(i=; i<=n; i++)scanf("%d",&a[i]),s+=a[i];
s/=;
memset(b,,sizeof(b));
for(i=; i<=n; i++)
{
for(j=; j<=s; j++)
{
if(b[i-][j])
{
b[i][j+a[i]]=ma(b[i][j+a[i]],b[i-][j]+a[i]);
b[i][j-a[i]>?j-a[i]:a[i]-j]=ma(b[i][j-a[i]>?j-a[i]:a[i]-j],ma(b[i-][j],b[i-][j]-j+a[i]));
}
}
b[i][a[i]]=ma(a[i],b[i][a[i]]);
for(j=; j<=s; j++)
b[i][j]=ma(b[i-][j],b[i][j]);
}
if(b[n][])
printf("%d\n",b[n][]);
else puts("Sorry");
}
}
The Twin Towers zoj2059 DP的更多相关文章
- LightOJ1126 Building Twin Towers(DP)
		
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1126 Description Professor Sofdor Al ...
 - ZOJ 2059 The Twin Towers(双塔DP)
		
The Twin Towers Time Limit: 2 Seconds Memory Limit: 65536 KB Twin towers we see you standing ta ...
 - lightoj 1126 - Building Twin Towers(dp,递推)
		
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1126 题解:一道基础的dp就是简单的递推可以设dp[height_left][ ...
 - UVA.10066 The Twin Towers (DP LCS)
		
UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化 ...
 - UVA 10066 The Twin Towers
		
裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algori ...
 - UVA 10066 The Twin Towers(LCS)
		
Problem B The Twin Towers Input: standard input Output: standard output Once upon a time, in an anci ...
 - uva 10066 The Twin Towers (最长公共子)
		
uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> # ...
 - UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
		
链接:UVa 10192 题意:给定两个字符串.求最长公共子串的长度 思路:这个是最长公共子串的直接应用 #include<stdio.h> #include<string.h> ...
 - Codeforces Round #273 (Div. 2) D. Red-Green Towers 背包dp
		
D. Red-Green Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
 
随机推荐
- Git安装配置(完整版)
			
首先安装Windows客户端的git和TortoiseGit. 安装这两个软件还是蛮重要的,很多选项不能乱选. 为了写个完整的博客,我是装了又卸,卸了又装. 1.安装git 下载:https://gi ...
 - Android检查更新下载安装
			
检查更新是任何app都会用到功能,任何一个app都不可能第一个版本就能把所有的需求都能实现,通过不断的挖掘需求迭代才能使app变的越来越好.检查更新自动下载安装分以下几个步骤: 请求服务器判断是否有最 ...
 - javascript如何用递归写一个简单的树形结构
			
现在有一个数据,需要你渲染出对应的列表出来: var data = [ {"id":1}, {"id":2}, {"id":3}, {&qu ...
 - mongodb 的服务启动和基本操作命令
			
由于在dos 下操作mongodb 很不方便 所以我推荐大家使用mongodb 的可视化工具robomongo 这个是robomongo的下载网址 https://robomongo.org/dow ...
 - 程序员也是弱势群体?——从WePhone开发者事件说起
			
作为一名不爱凑热闹的人,今天一直在持续关注一个热点事件--WePhone开发者自杀,即使前几天热议的孕妇跳楼新闻我都不太关注,但是这个事件却让我深深的震撼,花了几个小时在微博上搜索了相关的信息,去了解 ...
 - javascript 代码放在head和body的区别
			
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt239 1,在head中时,所代表的functions只加载而不执行,执行是在 ...
 - 学习Python Day1
			
学习PythonDay1,主要是学习了循环,while循环,for循环:while循环加if.else以及elif,for循环嵌套for循环:break,终止循环,continue跳出循环:for i ...
 - 转:【Java并发编程】之十:使用wait/notify/notifyAll实现线程间通信的几点重要说明
			
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17225469 在Java中,可以通过配合调用Object对象的wait()方法和no ...
 - 结对编程1 (四则运算基于GUI)
			
https://git.coding.net/Luo_yujie/sizeyunsuan.app.git 201421123034 201421123032 1. 需求分析 这次作业新引用了语言选择, ...
 - 【1414软工助教】团队作业6——展示博客(Alpha版本) 得分榜
			
题目 团队作业6--展示博客(Alpha版本) 作业提交情况情况 为所欲为 团队没有提交,其余都按时提交. 往期成绩 个人作业1:四则运算控制台 结对项目1:GUI 个人作业2:案例分析 结对项目2: ...