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 ...
随机推荐
- sed武功心法(info sed翻译+注解)
本文中的提到GNU扩展时,表示该功能是GNU为sed提供的(即GNU版本的sed才有该功能),一般此时都会说明:如果要写具有可移植性的脚本,应尽量避免在脚本中使用该选项. 本文中的正则表达式几乎和gr ...
- oracle语句批处理
数据量有40万条,从一个对象table_01一条一条取数到对象table_02,如果用原始的 Statement Statmt =comm.createStatement(); String sql= ...
- 两个input在同一行连着不留缝隙
方法1:让两个input 连在一起写 不换行 <div class="inputDiv"> <input type="text" placeh ...
- Keil提示premature end of file错误 无法生成HEX文件
今天舍友在使用Keil UV4的时候遇到一个问题:Keil提示premature end of file,无法生成hex文件. 代码是没有错误的.那么问题就出在设置上面了. 百度了一圈,发现很少人解答 ...
- SQL Server 2014 64位版本链接32位Oracle数据库
问题背景: 刚进入公司不久的BI新手,最近接部门的一个交接项目,需要在SQL Server上通过openquery来获取Oracle数据库的数据.各种配置,各种设置折腾了一周之久.在此,将自己的问题解 ...
- java.lang.reflect.MalformedParameterizedTypeException异常问题
做dubbo框架集成的时候,出现的问题,本来的原来的工程没有错误,引入dubbo后报错,原因是spring的jar文件冲突,我用的spring是4.x,dubbo引入的是2.5所以需要去掉,相关的po ...
- Haproxy基于ACL做访问控制
author:JevonWei 版权声明:原创作品 haproxy配置文档 https://cbonte.github.io/haproxy-dconv/ 基于ACL做访问控制(四层代理) 网络拓扑 ...
- 改变input光标颜色与输入字体颜色不同
设置input css: color #ffd600text-shadow 0px 0px 0px #bababa -webkit-text-fill-color initial input, tex ...
- NHibernate教程(21)——二级缓存(下)
本节内容 引入 使用NHibernate二级缓存 启用缓存查询 管理NHibernate二级缓存 结语 引入 这篇我还继续上一篇的话题聊聊NHibernate二级缓存剩下的内容,比如你修改.删除数据时 ...
- Bootstrap框架菜鸟入门教程
Bootstrap菜鸟入门教程 Bootstrap简介 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简 ...