Artifact Content
Not logged in

Artifact 52a3481b42a5f21129db8e1b441e09ed901c2391


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned x):val(x%MODVAL) {}
	mint(LL       x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator*(mint x, mint y) { return x*=y; }

class TrafficCongestion { public:
	int theMinCars(int treeHeight)
	{
		vector<mint> dp(treeHeight+1);
		vector<mint> sum(treeHeight+1);
		dp[0] = 1;
		sum[0] = dp[0];
		dp[1] = 1;
		sum[1] = dp[1] + sum[0];
		for(int h=2; h<=treeHeight; ++h)
		{
			dp[h] = sum[h-2]*2 + 1;
			sum[h] = dp[h] + sum[h-1];
		}
		return dp[treeHeight].val;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TrafficCongestion().theMinCars(treeHeight));}
int main(){

CASE(0)
	int treeHeight = 1; 
	int _ = 1; 
END
CASE(1)
	int treeHeight = 2; 
	int _ = 3; 
END
CASE(2)
	int treeHeight = 3; 
	int _ = 5; 
END
CASE(3)
	int treeHeight = 585858; 
	int _ = 548973404; 
END
CASE(4)
	int treeHeight = 5; 
	int _ = -1; 
END
/*
CASE(5)
	int treeHeight = ; 
	int _ = ; 
END
*/
}
// END CUT HERE