7f9fcaa19c 2013-08-02 kinaba: #include <iostream> 7f9fcaa19c 2013-08-02 kinaba: #include <sstream> 7f9fcaa19c 2013-08-02 kinaba: #include <iomanip> 7f9fcaa19c 2013-08-02 kinaba: #include <vector> 7f9fcaa19c 2013-08-02 kinaba: #include <string> 7f9fcaa19c 2013-08-02 kinaba: #include <map> 7f9fcaa19c 2013-08-02 kinaba: #include <set> 7f9fcaa19c 2013-08-02 kinaba: #include <algorithm> 7f9fcaa19c 2013-08-02 kinaba: #include <numeric> 7f9fcaa19c 2013-08-02 kinaba: #include <iterator> 7f9fcaa19c 2013-08-02 kinaba: #include <functional> 7f9fcaa19c 2013-08-02 kinaba: #include <complex> 7f9fcaa19c 2013-08-02 kinaba: #include <queue> 7f9fcaa19c 2013-08-02 kinaba: #include <stack> 7f9fcaa19c 2013-08-02 kinaba: #include <cmath> 7f9fcaa19c 2013-08-02 kinaba: #include <cassert> 7f9fcaa19c 2013-08-02 kinaba: #include <tuple> 7f9fcaa19c 2013-08-02 kinaba: using namespace std; 7f9fcaa19c 2013-08-02 kinaba: typedef long long LL; 7f9fcaa19c 2013-08-02 kinaba: typedef complex<double> CMP; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: static const unsigned MODVAL = 1000000007; 7f9fcaa19c 2013-08-02 kinaba: struct mint 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: unsigned val; 7f9fcaa19c 2013-08-02 kinaba: mint():val(0){} 7f9fcaa19c 2013-08-02 kinaba: mint(int x):val(x%MODVAL) {} 7f9fcaa19c 2013-08-02 kinaba: mint(unsigned x):val(x%MODVAL) {} 7f9fcaa19c 2013-08-02 kinaba: mint(LL x):val(x%MODVAL) {} 7f9fcaa19c 2013-08-02 kinaba: }; 7f9fcaa19c 2013-08-02 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 7f9fcaa19c 2013-08-02 kinaba: mint operator+(mint x, mint y) { return x+=y; } 7f9fcaa19c 2013-08-02 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 7f9fcaa19c 2013-08-02 kinaba: mint operator*(mint x, mint y) { return x*=y; } 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: class TrafficCongestion { public: 7f9fcaa19c 2013-08-02 kinaba: int theMinCars(int treeHeight) 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: vector<mint> dp(treeHeight+1); 7f9fcaa19c 2013-08-02 kinaba: vector<mint> sum(treeHeight+1); 7f9fcaa19c 2013-08-02 kinaba: dp[0] = 1; 7f9fcaa19c 2013-08-02 kinaba: sum[0] = dp[0]; 7f9fcaa19c 2013-08-02 kinaba: dp[1] = 1; 7f9fcaa19c 2013-08-02 kinaba: sum[1] = dp[1] + sum[0]; 7f9fcaa19c 2013-08-02 kinaba: for(int h=2; h<=treeHeight; ++h) 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: dp[h] = sum[h-2]*2 + 1; 7f9fcaa19c 2013-08-02 kinaba: sum[h] = dp[h] + sum[h-1]; 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: return dp[treeHeight].val; 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: }; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: // BEGIN CUT HERE 7f9fcaa19c 2013-08-02 kinaba: #include <ctime> 7f9fcaa19c 2013-08-02 kinaba: double start_time; string timer() 7f9fcaa19c 2013-08-02 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 7f9fcaa19c 2013-08-02 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 7f9fcaa19c 2013-08-02 kinaba: { os << "{ "; 7f9fcaa19c 2013-08-02 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 7f9fcaa19c 2013-08-02 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 7f9fcaa19c 2013-08-02 kinaba: void verify_case(const int& Expected, const int& Received) { 7f9fcaa19c 2013-08-02 kinaba: bool ok = (Expected == Received); 7f9fcaa19c 2013-08-02 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 7f9fcaa19c 2013-08-02 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 7f9fcaa19c 2013-08-02 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 7f9fcaa19c 2013-08-02 kinaba: #define END verify_case(_, TrafficCongestion().theMinCars(treeHeight));} 7f9fcaa19c 2013-08-02 kinaba: int main(){ 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: CASE(0) 7f9fcaa19c 2013-08-02 kinaba: int treeHeight = 1; 7f9fcaa19c 2013-08-02 kinaba: int _ = 1; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(1) 7f9fcaa19c 2013-08-02 kinaba: int treeHeight = 2; 7f9fcaa19c 2013-08-02 kinaba: int _ = 3; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(2) 7f9fcaa19c 2013-08-02 kinaba: int treeHeight = 3; 7f9fcaa19c 2013-08-02 kinaba: int _ = 5; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(3) 7f9fcaa19c 2013-08-02 kinaba: int treeHeight = 585858; 7f9fcaa19c 2013-08-02 kinaba: int _ = 548973404; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(4) 7f9fcaa19c 2013-08-02 kinaba: int treeHeight = 5; 7f9fcaa19c 2013-08-02 kinaba: int _ = -1; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: /* 7f9fcaa19c 2013-08-02 kinaba: CASE(5) 7f9fcaa19c 2013-08-02 kinaba: int treeHeight = ; 7f9fcaa19c 2013-08-02 kinaba: int _ = ; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: */ 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: // END CUT HERE