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 co…
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1126 Description Professor Sofdor Ali is fascinated about twin towers. So, in this problem you are working as his assistant, and you have to help him making a large twin towers. For this…
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…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1126 题解:一道基础的dp就是简单的递推可以设dp[height_left][height_right],但是这样显然回boom内存,所以不妨直接考虑两座塔之间的差于是便有了dp[i][j]表示考虑到第几个时两座塔差值是多少,然后就是递推了,要么加积木嫁到高的塔上要么就嫁到底的塔上要么都不嫁,这样递推方程就好写了.如果这样还是boom内存的话可以考虑用滚动优化i这一维. #i…
UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化为LCS(最长公共子序列)问题. 推荐一篇写的比较好的博文: 动态规划求解最长公共子序列(LCS) 核心的状态转移方程: if(a[i] == b[j]) dp[i][j] = dp[i-1][j-1] +1; else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);…
裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algorithm> #include<math.h> #include <string.h> #include<vector> #include<queue> using namespace std; ][]; ],map2[]; int main() { int…
Problem B The Twin Towers Input: standard input Output: standard output Once upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers were built by putting circular tiles one upon another. Each…
uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; int a[105], b[105], dp[105][105]; int main() { int n, m, Case = 1; while (scanf(&quo…
链接:UVa 10192 题意:给定两个字符串.求最长公共子串的长度 思路:这个是最长公共子串的直接应用 #include<stdio.h> #include<string.h> int max(int a,int b) { return a>b?a:b; } int main() { char s[105],t[105]; int i,j,k=0,m,n,dp[105][105]; while(gets(s)!=NULL){ if(strcmp(s,"#"…
D. Red-Green Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next…
双塔DP. dp[i][j]表示前i个物品,分成两堆(可以不全用),价值之差为j的时候,较小一堆的价值为dp[i][j]. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; ][ + ]; ]; int n, sum; void read() { ; i <= n; i++) scanf("%d",…
整理图书 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 小明是图书鹳狸猿,他有很多很多的书堆在了一起摆在了架子上,每摞书是横着放的,而且每摞书是订好的 是一个整体,不可分开,(可以想象架子是一条直线),但是这些书高度却参差不齐,小明有强迫症,看不得不整齐 所以他想让这些书的高度形成一个非降序列他才舒心,可是这些书是有序的,所以他只能把其中的一摞书和他相邻的书装订在一起 形成一摞新的书,那么他最少的装订次数是多少呢   输入 多组测试数据,处理到文件结束每组数据…
题目链接:http://codeforces.com/problemset/problem/478/D 题意: 给你r个红方块和g个绿方块,让你用这些方块堆一个塔. 最高层有1个方块,每往下一层块数+1,同时要保证每层中的方块都是同一种颜色. 如图: 问你在塔的高度最高的前提下,堆出塔的方案数. 题解: 假设塔最高能堆d层,则: d*(d+1)/2 <= r+g 解得: d = floor((-1+sqrt(1+8*(r+g)))/2) 并且d最大不超过900. 表示状态: dp[i][j] =…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i](一定是5的倍数),价值为w[i]. 一块高度>=t的奶酪被称为大奶酪,一个奶酪如果在它上方有大奶酪(多块只算一次),它的高度就会变成原来的4/5. John想让他的奶酪他价值和最大,求这个最大值. 题解: 方法一: dp + 贪心. 贪心:如果奶酪塔中有大奶酪,则大奶酪一定放在最上面. (1)有大奶…
http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那么我们就可以枚举每一个比k大的放在最顶,其它的都放在下边即可. 还有,注意这是完全背包! #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <i…
P2979 [USACO10JAN]奶酪塔Cheese Towers 背包dp 不过多了一个大奶酪可以压扁其他奶酪的 一开始写了个暴力82分.贪心的选择 然后发现,有如下两种规律 要么最优都是小奶酪,要么就是有一个大奶酪是在顶上的. 所以我们先用小奶酪跑一遍背包,记录最优值. 然后加上大奶酪,不考虑压缩的再跑一遍.因为如果大奶酪在上面的话,我们就不用考虑在dp中压缩,直接跑完dp后.看做一大块一起压缩 #include<iostream> #include<algorithm> #…
LIS(最长递增子序列)和LCS(最长公共子序列)的总结 最长公共子序列(LCS):O(n^2) 两个for循环让两个字符串按位的匹配:i in range(1, len1) j in range(1, len2) s1[i - 1] == s2[j - 1], dp[i][j] = dp[i - 1][j -1] + 1; s1[i - 1] != s2[j - 1], dp[i][j] = max (dp[i - 1][j], dp[i][j - 1]); 初始化:dp[i][0] = dp…
111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence LCS 674 - Coin Change 全然背包求方案数 10003  - Cutting Sticks 区间DP dp[l][r]代表分割l到r的最小费用 116 - Unidirectional TSP 简单递推 输出字典序最小解 从后往前推 10131 - Is Bigger Smarte…
/* 最长公共子序列 */ #include <cstdio> #include <string.h> #include <iostream> const int maxn=105; int N[maxn],M[maxn]; int dp[2][maxn]; int main() { int i,j,n,m,num=0; while(true){ scanf("%d%d",&n,&m); if(n==0&&m==0)…
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive…
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes…
2012.12.26 Hi all, How are you doing? Merry post-Christmas and happy upcoming New year!! I wish you had a good one this year. Our one week one time English corner is coming back! Are you excited to hear that. I know that you cannot wait to join us. Y…
My desperate journey with a human smuggler By Barat Ali Batoor When I was a child there was a toy where you could put square, round, triangular and star shapes through appropriate holes. A person is almost infinitely(无限地:极其) more complex than one of…
D. Red-Green Towers   There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: Red-green tower is consisting of some number of levels; Let the red-green tower consist of n levels,…
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意 :n个圆盘,m个柱子的汉诺塔输出步骤. http://acm.sgu.ru/problem.php?contest=0&problem=202 经典的递归问题,见具体数学第一章 先DP求出最短步骤,并记录路径. 然后 递归输出. import java.util.*; import java.io.*; import java.math.*;…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1059 分析:dp[i][j]表示前i个石头组成两座塔高度差为j的较低塔最大高度 状态转移: 每次石头都有三种方法: 1.放在高塔上:dp[i][j]=max(dp[i][j+t],dp[i][j]);低塔不变 2.放在低塔上:1)dp[i][j]=max(dp[i][j-t],dp[i][j]);低塔仍是较低塔 2)dp[i][j]=max(dp[i][t-j],d…
题意:给定 n 块红砖,m 块绿砖,问有多少种方式可以建造成最高的塔,每一层颜色必须一样. 析:首先要确定最高是多少层h,大约应该是用 h * (h+1) <= (m+n) * 2,然后dp[i][j] 表示 前 i 层用 j 块红砖,dp[i][j] += dp[i-1][j-i], 但是这个空间复杂度受不了,那么就变成滚动数组就好,dp[j] += dp[j-i],一个较简单的DP. 代码如下: #pragma comment(linker, "/STACK:1024000000,10…
题目链接 http://codeforces.com/problemset/problem/478/D 题意 叠放塔:有红.绿两种色块.从第一层开始,第一层1块,第二层2块,第i层i块. 要求每一层只能用同一种颜色的块. 输入:红块和绿块数目 输出:能叠放出的最高高度h的塔的种数.定义塔某一层的颜色不同,则为不同种. 题解 状态表示 dp[i][j]表示i层的塔,使用了j个红块 转移方程 dp[i][j]=dp[i-1][j]+dp[i-1][j-i],当j>=i dp[i][j]=dp[i-1…
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 不易: , , , , , , , , , , , , , , , , , , , , , , , , 推荐: , , , , , , , , , , , , , , , , , , , , , , , , Jury Compromise False co…
Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1219    Accepted Submission(s): 361 Problem Description FSF is addicted to a stupid tower defense game. The goal of tower…