题意:。。。

析:由于能最后一个是特殊的,所以前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 (递推)的更多相关文章

  1. HDU 2077 汉诺塔IV (递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2077 还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是 ...

  2. 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 ...

  3. HDU 2064 汉诺塔III (递推)

    题意:.. 析:dp[i] 表示把 i 个盘子搬到第 3 个柱子上最少步数,那么产生先把 i-1 个盘子搬到 第3个上,再把第 i 个搬到 第 2 个上,然后再把 i-1 个盘子, 从第3个柱子搬到第 ...

  4. 汉诺塔III 递推题

    题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...

  5. 2077 汉诺塔IV

    Problem Description 还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到小盘的上面.xhd在想 ...

  6. 汉诺塔VII(递推,模拟)

    汉诺塔VII Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  7. 汉诺塔III 汉诺塔IV 汉诺塔V (规律)

    汉诺塔III Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  8. hdu 1207 汉诺塔II (DP+递推)

    汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  9. HDU 2064 汉诺塔III (递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2064 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到 ...

随机推荐

  1. ZT:三十个好习惯

  2. LeetCode 3_Longest Substring Without Repeating Characters

    LeetCode 3_Longest Substring Without Repeating Characters 题目描写叙述: Given a string, find the length of ...

  3. memcached优化方法

    工作原理     基本概念:slab,page.chunk.     slab,是一个逻辑概念. 它是在启动memcached实例的时候预处理好的,每一个slab相应一个chunk size.也就是说 ...

  4. 卸载 linux http

    当我们想卸载httpd 的时候,使用rpm -qa httpd 的时候,我们发现有很多的依赖包.我们耐心的想一个一个的卸载的时候(使用rpm -e httpd-*),还会进入死循环.解决的办法是:使用 ...

  5. typedef和#define的差别——————【Badboy】

    typedef 和#define 都经常使用来定义一个标识符及keyword的别名.但他们之间有关键的差别. typedef 是语言编译过程的一部分; #define是宏定义语句,它本身并不在编译过程 ...

  6. The most widely used name server software: BIND

    https://www.isc.org/downloads/bind/ The most widely used name server software: BIND BIND is open sou ...

  7. 基于bootstrap_网站汇总页面

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Django-权限信息初始化

    数据库 from django.db import models class Menu(models.Model): """ 菜单组: """ ...

  9. 解压Zip

    import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import ja ...

  10. 利用PHP判断iPhone、iPad、Android、PC设备

    首页那张大图确实是一个比较头疼的问题 在PC上显示是没问题的,可是到手机上就会超出页面一大截,如果做自适应,图片会被强制压缩 无奈只能用wp_is_mobile()函数在手机上隐藏了这张图,可是这函数 ...