ZOJ 2059 The Twin Towers(双塔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…
双塔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",…
题目 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 co…
用dp[i][j]表示当前安排好了前i个任务,且机器A和机器B完成当前分配到的所有任务的时间差为j(这里j可正可负,实现的时候需要加个offset)时,完成这些任务的最早时间.然后根据j的正负,分别考虑任务i+1的两种分配方法.比如j大于0,A比B后空闲,这个时候如果再把任务分配给A的话,B空闲知道A开始处理i+1的这段时间,B是不能安排任务的,也就是说可以看成是非空闲的状态,于是下一个状态的A和B时间差就是i+1任务的长度. 就根据这个思路分几个情况进行处理,可以知道j这维不会超过100(就是…
题目链接: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]);…
Process the Tasks Time Limit: 1 Second      Memory Limit: 32768 KB There are two machines A and B. There are n tasks, namely task 1, task 2, ..., task n. You must assign each task to one machine to process it. There are some facts you must know and c…
裸最长公共子序列 #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,"#"…
第二次遇到双塔DP,再写一下. (flag是为了避免memset多次导致的时间浪费) #include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> using namespace std; ],y[],z[]; ][],L,Lx;//410=210+x bool _find(int flag) { ;i<=L;i++) { ;j<=min(Lx,i);j++) ][…
Greedy Tino Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1194    Accepted Submission(s): 393 Problem Description   Tino wrote a long long story. BUT! in Chinese...   So I have to tell you th…
Ferry Loading Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1807   Accepted: 509   Special Judge Description Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run…
描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件,Mr. F决定自己用水晶来搭建一座双塔. Mr. F有N块水晶,每块水晶有一个高度,他想用这N块水晶搭建两座有同样高度的塔,使他们成为一座双塔,Mr. F可以从这N块水晶中任取M(1≤M≤N)块来搭建.但是他不知道能否使两座塔有同样的高度,也不知道如果能搭建成一座双塔,这座双塔的最大高度是多少.所以他来请你帮忙. 给定水晶的数量N(1≤N≤100)和每块水晶的高度H…
题目链接:  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3494 题目大意:给定一些被禁止的BCD码.问指定范围内不含有任何这些禁止的BCD码的数的个数. 解题思路: AC自动机部分: 首先insert这些被禁止的BCD码. 然后打一下自动机前后状态的转移的表,用BCD[i][j]表示自动机状态i时,下一个数字是j的自动机的下一个状态. 一开始我考虑最先dfs的位在自动机的位置,后来发现SB了.AC自动机有一个roo…
题意:n个数字的串,每取出一个数字的代价为该数字和左右的乘积(1.n不能取),问最小代价 思路:dp[i][j]表示把i~j取到只剩 i.j 的最小代价. 代码: #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<cstring> #include<algorithm> typedef long lon…
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…
题目链接: POJ:id=3132">http://poj.org/problem?id=3132 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2822 Description A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two…
zoj 上次的月赛题,相当牛的题目啊,根本想不到是状态压缩好吧 有个预先要知道的,即500个16相加那也是不会超过8192,即,合并最多合并到4096,只有2的12次方 所以用状态压缩表示前面有的序列组合,找到了符合的,就往上累加合并生成新状态,否则就添加到前面的状态的后面构成新状态,因为每一个的状态都由前一个所得,用滚动数组即可 #include <iostream> #include <cstdio> #include <cstring> #include <…
参考:http://blog.csdn.net/qian99/article/details/39138329 参考的链接里说明得很好,注释也很好...thanks for sharing 朴素的想法不难,dp[i][j][k]类似背包做法即可. 但朴素思想复杂度过高. 这里主要是用到 dif 那个变量,只枚举新增的集合. #include <cstdio> #include <cstring> #include <iostream> #include <algo…
Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there is a control panel with four direction left (1st position),…
题目大意:不超过10种气体,两两之间相互碰撞可以产生一定的能量,如a碰b,那么b气体就消失,自身不能碰自身,问最后所能得到的最大能量. 原代码链接:http://blog.csdn.net/accry/article/details/6607703 题解:感觉这个题是我做状态压缩的几个题中最简单的了,这存图用a数组就可以了,也不用处理a数组(有的求路径的题要用弗洛伊德处理原数组),因为碰撞是不可逆的. 接着就用s开始从0枚举状态到1<<N-1,还要注意去掉不可能的情况!! AC代码: #inc…
首先要吐两行槽:看到集训队论文上有这道题,由于数位DP一律写成记忆化搜索形式的强迫症,就没去看论文上的几个函数是什么……:结果被这道题虐的脑细胞死光……,最后是用随机数据对拍AC程序然后发现BUG改掉后才过掉的,花了一整天时间…….回头看论文,发现差不多……. 大概题意:给出一个long long范围的数N构成区间[1,N]和K(K<N),然后给出数的排名规则(参见原题),看到第一问求K的排名,稍稍考虑后觉得……这还用做?,第二问求第K大的数是什么,脑补N久之后感叹……这也能做?!  好吧,第一…
题目链接 题意 : 给你两个长度为N的字符串,将第一个字符串每次只能变化M个,问变换K次之后变成第二个字符串一共有几种方法. 思路 : DP.dp[i][j]表示变了 i 次之后有j个不一样的字母的方法数. 状态转移方程:dp[i+1][j+M-2*k] += (dp[i][j]*(c[j][k]*c[N-j][M-k]) ; c[j][k]表示的是从j个不匹配的字符中找出k个不匹配,所以c[N-j][M-k]表示的剩下的N-j个中挑出M-k个匹配的进行变换.两者相乘就是组合数,表明这次变换的方…
题目链接 题意 : 给你两个字符串,两个字符串都有共同的字母,给你每个字母的值,规则是,找出两个字符串中的共同的一个字母,然后这个字母的值就可以加到自己的分数上,但是这步操作之后,这两个字母及其之前的字母都要删除掉,问你能够得到的最大的值是什么. 思路:最长公共子序列,加了一个权值. #include <iostream> #include <stdio.h> #include <string> #include <string.h> using names…
题意: 三个色子有k1,2,k3个面每面标号(1-k1,1-k2,1-k3),一次抛三个色子,得正面向上的三个编号,若这三个标号和给定的三个编号a1,b1,c1对应则总和置零,否则总和加上三个色子标号和,直到总和不小于n时结束,求抛色子的期望次数. 分析: 该题状态好分析 dp[i]表示和为i时的期望次数,dp[0]是答案 dp[i]=sum(dp[i+tmp]*p[tmp])+dp[0]*p0+1(tmp是三个色子可得到的标号和); 第一次看到这样的方程不怎么解,看了题解才知道用迭代法,每个d…
记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll __int64 #define pi acos(-1.0) #define MAX 50000 using names…
思路:这题的递推方程有点麻烦!! dp[i]表示分数为i的期望步数,p[k]表示得分为k的概率,p0表示回到0的概率: dp[i]=Σ(p[k]*dp[i+k])+dp[0]*p0+1 设dp[i]=A[i]*dp[0]+B[i]带入的: dp[i]=∑(pk*A[i+k]*dp[0]+pk*B[i+k])+dp[0]*p0+1       =(∑(pk*A[i+k])+p0)dp[0]+∑(pk*B[i+k])+1;     明显A[i]=(∑(pk*A[i+k])+p0)     B[i]=…