3 2 8 12
3 171 2731
思路:递推,公式为 a[n] = a[n-1] + 2*a[n-2];
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[31] = {0, 1, 3}; void init() { for(int i=3; i<31; i++) a[i] = a[i-1] + 2*a[i-2]; } int main() { init(); int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); printf("%d\n", a[n]); } return 0; }
HDU - 2501 - Tiling_easy version (简单递推关系!!)
原文地址:http://blog.csdn.net/u014355480/article/details/42090533