标签:-- 字符串个数 pre ble acm iostream ios pow 成长
#include <iostream> using namespace std; long long a[41] = { 0, 3, 8 }; // O,E 组成长度为n的数量 long long fib(int n) { if (n == 1) return 2; if (n == 2) return 3; long long f1 = 2; long long f2 = 3; while (n >= 3) { long long f3 = f1 + f2; f1 = f2; f2 = f3; n--; } return f2; } int main() { int n; long long b[41]; b[1] = 3; b[2] = 8; for (int i = 3; i <= 40; i++) { // 规律不对 // 2^n -2 是只有EF组成长度为n的字符串个数 //b[i] = 2 * fib(i) + pow(2, i) - 2; a[i] = 2 * (a[i - 1] + a[i - 2]); } while (cin >> n) { cout << a[n] << endl; } }
http://acm.hdu.edu.cn/showproblem.php?pid=2047
标签:-- 字符串个数 pre ble acm iostream ios pow 成长
原文地址:http://www.cnblogs.com/theskulls/p/6011653.html