HDU 2190 简单递推
来源:互联网 发布:淘宝恒源祥羊毛衫价格 编辑:程序博客网 时间:2024/04/30 11:06
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2190
思路:对于n米的长度,可以是由n-1长度加1而来,对于增加的1,只有三块1*1的砖一种铺法;还可以是由n-2唱的加2而来,对于增加的2,有一块2*2和两块1*1两种铺法(2*2在上或在下),于是得递推公式为a[n] = a[n-1] + 2 * a[n-2]
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <map>#include <cmath>#include <string>#include <sstream>#include <cctype>#include <queue>using namespace std;int main(){ int a[35] = {0, 1, 3, 5}; for(int i = 4; i <= 30; i++) a[i] = a[i-1] + 2 * a[i-2]; int t, n; scanf("%d", &t); while(t--) { scanf("%d", &n); printf("%d\n", a[n]); } return 0;}
0 0
- HDU 2190 简单递推
- hdu 2046 简单递推
- hdu 2045(简单递推)
- HDU-超级阶梯(简单递推)
- HDU 2563 统计问题【简单递推】
- hdu 2047简单递推公式
- hdu 4472 Count(简单递推)
- hdu 5965(dp递推,简单题)
- HDU 2042 不容易系列之二【简单递推】
- HDU - 2501 - Tiling_easy version (简单递推关系!!)
- (hdu step 3.1.3)母牛的故事(简单递推)
- HDU 2046 骨牌铺方格(简单递推)
- HDU 2563 统计问题(简单递推/模拟)
- HDU 2046 骨牌铺方格 简单递推
- hdu 1165 递推
- HDU 2050 递推
- [HDU-1035] 递推
- hdu 1143 递推
- 表格布局
- 2016蓝桥杯假期任务之《回文数字》
- theano测试代码
- Convert Sorted List to Binary Search Tree
- 【计算机基础】堆和栈的区别(非数据结构中的堆和栈)
- HDU 2190 简单递推
- AsyncTask
- 二叉树的C++指针实现
- 杭电1284
- 仿微信的侧滑退出Activity
- 验证码图像识别-python
- 算法训练 学做菜
- 双重检查加锁机制--解决线程安全
- 【数据结构】堆