HDU 2064 汉诺塔III (递推)
题意:。。
析:dp[i] 表示把 i 个盘子搬到第 3 个柱子上最少步数,那么产生先把 i-1 个盘子搬到 第3个上,再把第 i 个搬到 第 2 个上,然后再把 i-1 个盘子,
从第3个柱子搬到第1个上,再把第 i 个盘子,搬到第3个上,再把第i-1个盘子从第1个柱子上搬到第3个上,所以总起来就是。
dp[i] = dp[i-1] * 3 + 2.
代码如下:
#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 < 36; ++i) dp[i] = dp[i-1] * 3LL + 2LL;
} int main(){
init();
while(cin >> n) cout << dp[n] << endl;
return 0;
}
HDU 2064 汉诺塔III (递推)的更多相关文章
- HDU 2064 汉诺塔III
汉诺塔III Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU——2064汉诺塔III
汉诺塔III Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU 2064 汉诺塔III (递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2064 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到 ...
- 汉诺塔III 递推题
题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...
- HDU 2064 汉诺塔III(递归)
题目链接 Problem Description 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘 ...
- HDU 2077 汉诺塔IV (递推)
题意:... 析:由于能最后一个是特殊的,所以前n-1个都是不变的,只是减少了最后一个盘子的次数,所以根据上一个题的结论 答案就是dp[n-1] + 2. 上一题链接:http://www.cnblo ...
- HDOJ.2064 汉诺塔III
汉诺塔III Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- [acm]HDOJ 2064 汉诺塔III
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2064 汉诺塔变种,只能从中间专业,递归关系为:f(n)=3*f(n-1)+2. //汉诺塔变种,只能 ...
- 汉诺塔VII(递推,模拟)
汉诺塔VII Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
随机推荐
- 【paddle学习】识别数字
Softmax回归(Softmax Regression) 最简单的Softmax回归模型是先将输入层经过一个全连接层得到的特征,然后直接通过softmax 函数进行多分类 输入层的数据$X$传到输出 ...
- 1 npoi 网上 不用模板 设置密码 workbook.WriteProtectWorkbook("password", "admin"); 、、 2 locked.IsLocked = true; sheet1.ProtectSheet("password");NPOI操作EXCEL--设置密码才可以修改单元格内容 3 模板设置密码 确定原密码 设置新密码
1 workbook.WriteProtectWorkbook("password", "admin"); 还是可以进去 只读进去 可以编辑 编辑就另存为 ...
- Nova虚拟机启动提示libvirtError
OpenStack自动化安装基本折腾完毕,装一次大概也就10分钟,但是装完后今天我的虚拟机起不来,经过查找log发 现如下图提示: 已经到这里,说明已经过了nova-sheduler那一关,跟踪一下代 ...
- linux getopt函数详解
getopt(分析命令行参数) 表头文件 #include<unistd.h> 定义函数 int getopt(int argc,char * const argv[ ],const ...
- C系列语言终极校对宝典【第一、第二部分】
第一部分:基本概念及其它问答题 1.关键字static的作用是什么? 这个简单的问题很少有人能回答完全.在C语言中,关键字static有三个明显的作用: 1). 在函数体,一个被声明为静态的变量在这一 ...
- DRF 之 认证组件
1.认证的作用? 我们知道,当我们在网站上登陆之后,就会有自己的个人中心,之类的可以对自己的信息进行修改.但是http请求又是无状态的,所以导致我们每次请求都是一个新的请求,服务端每次都需要对请求进行 ...
- SQL常见问题及解决备忘
1.mysql中:you cant't specify tartget table for update in from clause 错误 含义:在同一语句中update或delete某张表的时候, ...
- sql语句,无法绑定由多个部分组成的标识符 "xxx"
String sql = "select TOP 7 news_id,news_title,news_addtime,news_url from web_news_info a" ...
- Uboot中start.S源码的指令级的详尽解析【转】
本文转载自:http://www.crifan.com/files/doc/docbook/uboot_starts_analysis/release/html/uboot_starts_analys ...
- Couldn't connect to host, port: smtp.163.com, 25; timeout -1;
运行出现以下报错: Couldn't connect to host, port: smtp.163.com, 25; timeout -1; 也要设置端口 spring.mail.port=25