题目来源: http://community.topcoder.com/stat?c=problem_statement&pm=12697
分析题目, 画一画, 就可以找到规律了, 然后就很简单了.
代码如下:
using namespace std;
long long h[61];
class TrafficCongestionDivTwo {
public:
long long theMinCars(int treeHeight) {
for (int i = 0; i < 61; i++) {
h[i] = 0;
}
h[0] = 1;
h[1] = 1;
for (int i = 2; i <= 60; i++) {
h[i] = h[i - 1] + 2 * h[i - 2];
}
return h[treeHeight];
}
};