原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 题目分析:题目是真的水,不难发现规律涉及斐波那契数列,就直接上代码吧. 代码如下: #include <iostream> #include <cstring> using namespace std; int t, n, num[40]; int dp(int n) { if (n == 1 || n == 2) return num[n] = n; if (num[n] !=…
1225. Flags Time limit: 1.0 secondMemory limit: 64 MB On the Day of the Flag of Russia a shop-owner decided to decorate the show-window of his shop with textile stripes of white, blue and red colors. He wants to satisfy the following conditions: Stri…
斐波那契数列:1, 1, 2, 3, 5, 8, 13,...,即 f(n) = f(n-1) + f(n-2). 求第n个数的值. 方法一:迭代 public static int iterativeFibonacci(int n) { //简单迭代 int a = 1, b = 1; for(int i = 2; i < n; i ++) { int tmp = a + b; a = b; b = tmp; } return b; } 方法二:简单递归 public static long…