SGU 263. Towers】的更多相关文章

各种操作: put x c:表示在第 x 列上增加 c 个积木(c>0). tput t x c:表示在塔 t 的第 x 列上增加 c 个积木(c>0). towers:询问共有几座塔. cubes t:询问第 t 座塔共有几个积木. length t:询问第 t 座塔的长度. tcubes t x:询问第 t 座塔的第 x 列有几个积木. 对应做法: towers: 由于要查询tower的数目,以及删除一个tower,加入一个tower,考虑使用平衡树维护. put: 首先加积木这一件事情只…
转载请注明出处,谢谢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.*;…
多柱汉诺塔问题. 引用自wiki百科 多塔汉诺塔问题 在有3个柱子时,所需步数的公式较简单,但对于4个以上柱子的汉诺塔尚未得到通用公式,但有一递归公式(未得到证明,但目前为止没有找到反例): 令为在有k个柱子时,移动n个圆盘到另一柱子上需要的步数,则: 对于任何移动方法,必定会先将个圆盘移动到一个中间柱子上,再将第n到第n-m个圆盘通过剩下的k-1个柱子移到目标柱子上,最后将m个在中间柱子上的圆盘移动到目标柱子上.这样所需的操作步数为. 进行最优化,易得: . #include <bits/st…
题目 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…
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kilobytes input: standardoutput: standard ICPC (International Cardboard Producing Company) is in the business of producing cardboard boxes. Recently the…
裸最长公共子序列 #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…
sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Description Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The bl…
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则拿出礼物放回盒子,如果没有礼物则不操作.问M个人拿出礼物个数的期望.(N,M<=100000) #include <cstdio> using namespace std; double mpow(double a, int n) { double r=1; while(n) { if(n&…
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operations with int64 type, all Delphi solutions for the problem 455 (Sequence analysis) run much slower than the same code written in C++ or Java. We do not gua…
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且从当前光标删除到第一个出错的位置(留下的字符串要么为空,要么每个字符都是对的).问你,他正确的打完该字符串最少需要花费的时间的期望值是多少 字符串的长度小于等于3000 题意有点绕,具体可以看看原题是怎么描述的 做法分析 首先确定这是一个概率DP的问题. 定义状态 f[i] 表示正确的打完前 i 个…