HDU 2077 汉诺塔IV (递推)
题意:。。。
析:由于能最后一个是特殊的,所以前n-1个都是不变的,只是减少了最后一个盘子的次数,所以根据上一个题的结论 答案就是dp[n-1] + 2。
上一题链接:http://www.cnblogs.com/dwtfukgv/p/6283879.html
代码如下;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 40 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL dp[maxn]; void init(){
dp[1] = 2;
for(int i = 2; i < 21; ++i) dp[i] = dp[i-1] * 3LL + 2LL;
} int main(){
init();
int T; cin >> T;
while(T--){
cin >> n;
cout << dp[n-1] + 2LL << endl;
}
return 0;
}
HDU 2077 汉诺塔IV (递推)的更多相关文章
- HDU 2077 汉诺塔IV (递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2077 还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是 ...
- HDU 2077 汉诺塔IV 递归 通项公式
刚刚做的HDU 2064很好找规律, 回忆一下: b[1] = 2; b[n] = b[n-1] *3 + 2; 可得b[n]= 3^n-1 不懂的传送门http://blog.csdn.net/mu ...
- HDU 2064 汉诺塔III (递推)
题意:.. 析:dp[i] 表示把 i 个盘子搬到第 3 个柱子上最少步数,那么产生先把 i-1 个盘子搬到 第3个上,再把第 i 个搬到 第 2 个上,然后再把 i-1 个盘子, 从第3个柱子搬到第 ...
- 汉诺塔III 递推题
题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...
- 2077 汉诺塔IV
Problem Description 还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到小盘的上面.xhd在想 ...
- 汉诺塔VII(递推,模拟)
汉诺塔VII Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- 汉诺塔III 汉诺塔IV 汉诺塔V (规律)
汉诺塔III Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 1207 汉诺塔II (DP+递推)
汉诺塔II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 2064 汉诺塔III (递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2064 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到 ...
随机推荐
- BUPT复试专题—密码(2009)
题目描述 输入 有多组输入,每组: 第一行:由26个小写字母组成的串以空格隔开,如 b a c e u f g h i j k l m n o p q r s t v w x y z d v y ...
- malloc动态分配多维数组
下面试自己写的三个测试程序,如果看懂了基本上动态分配多维数组就没什么问题啦:重点 1:深刻理解多维数组的概念,多维数组在内存中的分配情况,基本上动态分配也没什么问题的.然后还要注意一点的就是,释放是分 ...
- python requests接收chunked编码问题-python源码修改
python requests接收chunked编码问题-python源码修改 学习了:https://blog.csdn.net/wangzuxi/article/details/40377467
- SolidEdge 工程图中如何给零件着色 给装配体着色
点击着色按钮,然后点击更新视图即可.
- Bootstrap的表单控件
支持的表单控件 Bootstrap 支持最常见的表单控件,主要是 input.textarea.checkbox.radio 和 select. 输入框(Input) 最常见的表单文本字段是输入框 i ...
- IO模型:同步、异步、阻塞、非阻塞
前言: 在Linux的网络编程中,同步IO(synchronous IO).异步IO(asynchronous IO).阻塞IO(blocking IO).非阻塞IO(non-blocking IO) ...
- 一道有关switch-case题目
一道有关switch-case题目 /** * * @title:SwitchCase.java * @Package:com.you.hbxs.model * @Description:<h3 ...
- angularjs学习之八(angularjs中isolate scope的使用)
angular js中指令directive有个特别实用的东西,那就是 isolate scope (被隔离的scope) 关于详细他和全局的scope 有什么差别.能够參考以下这篇博文: Angul ...
- hibernate工作原理及作用
转载自 http://www.cnblogs.com/dashi/p/3597969.html#commentform JAVA Hibernate工作原理及为什么要用 hibernate 简介:hi ...
- 如何删除ini文件中的内容
1.删除子项值:::WritePrivateProfileString(分区名称, 子项名称, "", ini文件路径); 2.删除子项(名称和值):::WritePrivateP ...