File Annotation
Not logged in
4fd800b3a8 2011-02-23        kinaba: #include <iostream>
4fd800b3a8 2011-02-23        kinaba: #include <sstream>
4fd800b3a8 2011-02-23        kinaba: #include <iomanip>
4fd800b3a8 2011-02-23        kinaba: #include <vector>
4fd800b3a8 2011-02-23        kinaba: #include <string>
4fd800b3a8 2011-02-23        kinaba: #include <map>
4fd800b3a8 2011-02-23        kinaba: #include <set>
4fd800b3a8 2011-02-23        kinaba: #include <algorithm>
4fd800b3a8 2011-02-23        kinaba: #include <numeric>
4fd800b3a8 2011-02-23        kinaba: #include <iterator>
4fd800b3a8 2011-02-23        kinaba: #include <functional>
4fd800b3a8 2011-02-23        kinaba: #include <complex>
4fd800b3a8 2011-02-23        kinaba: #include <queue>
4fd800b3a8 2011-02-23        kinaba: #include <stack>
4fd800b3a8 2011-02-23        kinaba: #include <cmath>
4fd800b3a8 2011-02-23        kinaba: #include <cassert>
4fd800b3a8 2011-02-23        kinaba: #include <cstring>
4fd800b3a8 2011-02-23        kinaba: using namespace std;
4fd800b3a8 2011-02-23        kinaba: typedef long long LL;
4fd800b3a8 2011-02-23        kinaba: typedef complex<double> CMP;
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: template<typename T>
4fd800b3a8 2011-02-23        kinaba: struct DP3
4fd800b3a8 2011-02-23        kinaba: {
4fd800b3a8 2011-02-23        kinaba: 	int N1, N2, N3;
4fd800b3a8 2011-02-23        kinaba: 	vector<T> data;
4fd800b3a8 2011-02-23        kinaba: 	DP3(int N1, int N2, int N3, const T& t = T())
4fd800b3a8 2011-02-23        kinaba: 		: N1(N1), N2(N2), N3(N3), data(N1*N2*N3, t) {}
4fd800b3a8 2011-02-23        kinaba: 	T& operator()(int i1, int i2, int i3)
4fd800b3a8 2011-02-23        kinaba: 		{ return data[ ((i1*N2)+i2)*N3+i3 ]; }
4fd800b3a8 2011-02-23        kinaba: 	void swap(DP3& rhs)
4fd800b3a8 2011-02-23        kinaba: 		{ data.swap(rhs.data); }
4fd800b3a8 2011-02-23        kinaba: };
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: class TheFansAndMeetingsDivOne { public:
4fd800b3a8 2011-02-23        kinaba: 	double find(vector <int> minJ, vector <int> maxJ, vector <int> minB, vector <int> maxB, int k)
4fd800b3a8 2011-02-23        kinaba: 	{
4fd800b3a8 2011-02-23        kinaba: 		const int N = minJ.size();
4fd800b3a8 2011-02-23        kinaba: 		const int S = max( accumulate(maxB.begin(), maxB.end(), 0), accumulate(maxJ.begin(), maxJ.end(), 0) );
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: 		DP3<double> dpJ(41,41,1601);
4fd800b3a8 2011-02-23        kinaba: 		dpJ(0,0,0) = 1.0;
4fd800b3a8 2011-02-23        kinaba: 		for(int i=1; i<=N; ++i)
4fd800b3a8 2011-02-23        kinaba: 		for(int vis=0; vis<=k; ++vis)
4fd800b3a8 2011-02-23        kinaba: 		for(int s=0; s<=S; ++s)
4fd800b3a8 2011-02-23        kinaba: 		{
4fd800b3a8 2011-02-23        kinaba: 			double PP = 0;
4fd800b3a8 2011-02-23        kinaba: 			if(vis)
4fd800b3a8 2011-02-23        kinaba: 				for(int p=minJ[i-1]; p<=maxJ[i-1] && p<=s; ++p)
4fd800b3a8 2011-02-23        kinaba: 					PP += dpJ(vis-1, i-1, s-p);
4fd800b3a8 2011-02-23        kinaba: 			dpJ(vis,i,s) = dpJ(vis, i-1, s) + PP / (maxJ[i-1]-minJ[i-1]+1);
4fd800b3a8 2011-02-23        kinaba: 		}
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: 		DP3<double> dpB(41,41,1601);
4fd800b3a8 2011-02-23        kinaba: 		dpB(0,0,0) = 1.0;
4fd800b3a8 2011-02-23        kinaba: 		for(int i=1; i<=N; ++i)
4fd800b3a8 2011-02-23        kinaba: 		for(int vis=0; vis<=k; ++vis)
4fd800b3a8 2011-02-23        kinaba: 		for(int s=0; s<=S; ++s)
4fd800b3a8 2011-02-23        kinaba: 		{
4fd800b3a8 2011-02-23        kinaba: 			double PP = 0;
4fd800b3a8 2011-02-23        kinaba: 			if(vis)
4fd800b3a8 2011-02-23        kinaba: 				for(int p=minB[i-1]; p<=maxB[i-1] && p<=s; ++p)
4fd800b3a8 2011-02-23        kinaba: 					PP += dpB(vis-1, i-1, s-p);
4fd800b3a8 2011-02-23        kinaba: 			dpB(vis,i,s) = dpB(vis, i-1, s) + PP / (maxB[i-1]-minB[i-1]+1);
4fd800b3a8 2011-02-23        kinaba: 		}
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: 		double ans = 0.0, nB=0.0, nJ=0.0;
4fd800b3a8 2011-02-23        kinaba: 		for(int s=0; s<=S; ++s)
4fd800b3a8 2011-02-23        kinaba: 			nB += dpB(k, N, s), nJ += dpJ(k, N, s);
4fd800b3a8 2011-02-23        kinaba: 		for(int s=0; s<=S; ++s)
4fd800b3a8 2011-02-23        kinaba: 			ans += dpB(k, N, s) * dpJ(k, N, s) / nB / nJ;
4fd800b3a8 2011-02-23        kinaba: 		return ans;
4fd800b3a8 2011-02-23        kinaba: 	}
4fd800b3a8 2011-02-23        kinaba: };
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: // BEGIN CUT HERE
4fd800b3a8 2011-02-23        kinaba: #include <ctime>
4fd800b3a8 2011-02-23        kinaba: double start_time; string timer()
4fd800b3a8 2011-02-23        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
4fd800b3a8 2011-02-23        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
4fd800b3a8 2011-02-23        kinaba:  { os << "{ ";
4fd800b3a8 2011-02-23        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
4fd800b3a8 2011-02-23        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
4fd800b3a8 2011-02-23        kinaba: void verify_case(const double& Expected, const double& Received) {
4fd800b3a8 2011-02-23        kinaba:  double diff = Expected - Received; if (diff < 0) diff = -diff; bool ok = (diff < 1e-9);
4fd800b3a8 2011-02-23        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
4fd800b3a8 2011-02-23        kinaba:  cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
4fd800b3a8 2011-02-23        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
4fd800b3a8 2011-02-23        kinaba: #define END	 verify_case(_, TheFansAndMeetingsDivOne().find(minJ, maxJ, minB, maxB, k));}
4fd800b3a8 2011-02-23        kinaba: int main(){
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: CASE(0)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {9};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {5};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {5};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 1;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 0.1111111111111111;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(0)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {5};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {5};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {9};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 1;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 0.1111111111111111;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(1)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {5, 2, 5, 1, 1, 2, 4, 1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {7, 6, 7, 3, 4, 3, 5, 1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {8, 9, 7, 11, 12, 7, 8, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {9, 10, 9, 33, 14, 7, 11, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 2;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 4.724111866969009E-5;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(1)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {8, 9, 7, 11, 12, 7, 8, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {9, 10, 9, 33, 14, 7, 11, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {5, 2, 5, 1, 1, 2, 4, 1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {7, 6, 7, 3, 4, 3, 5, 1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 2;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 4.724111866969009E-5;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(2)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {4, 7, 4};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {7, 7, 7};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {40, 40, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {40, 40, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 1;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 0.0;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(2)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {40, 40, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {40, 40, 40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {4, 7, 4};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {7, 7, 7};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 1;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 0.0;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(3)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {3, 6, 2, 1, 1, 10, 3};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {6, 9, 5, 6, 5, 10, 9};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {1, 1, 1, 1, 8, 3, 1};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {3, 9, 7, 3, 10, 6, 5};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 4;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 0.047082056525158976;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(4)
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {40};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 1;
4fd800b3a8 2011-02-23        kinaba: 	double _ = 1.0;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: CASE(5)
4fd800b3a8 2011-02-23        kinaba: //1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
4fd800b3a8 2011-02-23        kinaba: //40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40
4fd800b3a8 2011-02-23        kinaba: 	int minJ_[] = {1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_));
4fd800b3a8 2011-02-23        kinaba: 	int maxJ_[] = {30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_));
4fd800b3a8 2011-02-23        kinaba: 	int minB_[] = {1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_));
4fd800b3a8 2011-02-23        kinaba: 	int maxB_[] = {30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30};
4fd800b3a8 2011-02-23        kinaba: 	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_));
4fd800b3a8 2011-02-23        kinaba: 	int k = 40;
4fd800b3a8 2011-02-23        kinaba: 	double _ = -1;
4fd800b3a8 2011-02-23        kinaba: END
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: }
4fd800b3a8 2011-02-23        kinaba: // END CUT HERE