Artifact Content
Not logged in

Artifact 2b2ccff9854de3ab50be63e73b9d370f0d77ff1e


#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

template<typename T>
struct DP3
{
	int N1, N2, N3;
	vector<T> data;
	DP3(int N1, int N2, int N3, const T& t = T())
		: N1(N1), N2(N2), N3(N3), data(N1*N2*N3, t) {}
	T& operator()(int i1, int i2, int i3)
		{ return data[ ((i1*N2)+i2)*N3+i3 ]; }
	void swap(DP3& rhs)
		{ data.swap(rhs.data); }
};

class TheFansAndMeetingsDivOne { public:
	double find(vector <int> minJ, vector <int> maxJ, vector <int> minB, vector <int> maxB, int k) 
	{
		const int N = minJ.size();
		const int S = max( accumulate(maxB.begin(), maxB.end(), 0), accumulate(maxJ.begin(), maxJ.end(), 0) );

		DP3<double> dpJ(41,41,1601);
		dpJ(0,0,0) = 1.0;
		for(int i=1; i<=N; ++i)
		for(int vis=0; vis<=k; ++vis)
		for(int s=0; s<=S; ++s)
		{
			double PP = 0;
			if(vis)
				for(int p=minJ[i-1]; p<=maxJ[i-1] && p<=s; ++p)
					PP += dpJ(vis-1, i-1, s-p);
			dpJ(vis,i,s) = dpJ(vis, i-1, s) + PP / (maxJ[i-1]-minJ[i-1]+1);
		}

		DP3<double> dpB(41,41,1601);
		dpB(0,0,0) = 1.0;
		for(int i=1; i<=N; ++i)
		for(int vis=0; vis<=k; ++vis)
		for(int s=0; s<=S; ++s)
		{
			double PP = 0;
			if(vis)
				for(int p=minB[i-1]; p<=maxB[i-1] && p<=s; ++p)
					PP += dpB(vis-1, i-1, s-p);
			dpB(vis,i,s) = dpB(vis, i-1, s) + PP / (maxB[i-1]-minB[i-1]+1);
		}

		double ans = 0.0, nB=0.0, nJ=0.0;
		for(int s=0; s<=S; ++s)
			nB += dpB(k, N, s), nJ += dpJ(k, N, s);
		for(int s=0; s<=S; ++s)
			ans += dpB(k, N, s) * dpJ(k, N, s) / nB / nJ;
		return ans;
	}
};

// 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 double& Expected, const double& Received) {
 double diff = Expected - Received; if (diff < 0) diff = -diff; bool ok = (diff < 1e-9);
 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(_, TheFansAndMeetingsDivOne().find(minJ, maxJ, minB, maxB, k));}
int main(){

CASE(0)
	int minJ_[] = {1};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {9};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {5};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {5};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 1; 
	double _ = 0.1111111111111111; 
END
CASE(0)
	int minJ_[] = {5};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {5};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {1};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {9};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 1; 
	double _ = 0.1111111111111111; 
END
CASE(1)
	int minJ_[] = {5, 2, 5, 1, 1, 2, 4, 1};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {7, 6, 7, 3, 4, 3, 5, 1};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {8, 9, 7, 11, 12, 7, 8, 40};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {9, 10, 9, 33, 14, 7, 11, 40};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 2; 
	double _ = 4.724111866969009E-5; 
END
CASE(1)
	int minJ_[] = {8, 9, 7, 11, 12, 7, 8, 40};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {9, 10, 9, 33, 14, 7, 11, 40};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {5, 2, 5, 1, 1, 2, 4, 1};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {7, 6, 7, 3, 4, 3, 5, 1};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 2; 
	double _ = 4.724111866969009E-5; 
END
CASE(2)
	int minJ_[] = {4, 7, 4};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {7, 7, 7};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {40, 40, 40};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {40, 40, 40};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 1; 
	double _ = 0.0; 
END
CASE(2)
	int minJ_[] = {40, 40, 40};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {40, 40, 40};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {4, 7, 4};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {7, 7, 7};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 1; 
	double _ = 0.0; 
END
CASE(3)
	int minJ_[] = {3, 6, 2, 1, 1, 10, 3};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {6, 9, 5, 6, 5, 10, 9};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {1, 1, 1, 1, 8, 3, 1};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {3, 9, 7, 3, 10, 6, 5};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 4; 
	double _ = 0.047082056525158976; 
END
CASE(4)
	int minJ_[] = {40};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	int maxJ_[] = {40};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	int minB_[] = {40};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	int maxB_[] = {40};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 1; 
	double _ = 1.0; 
END
CASE(5)
//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
//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
	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};
	  vector <int> minJ(minJ_, minJ_+sizeof(minJ_)/sizeof(*minJ_)); 
	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};
	  vector <int> maxJ(maxJ_, maxJ_+sizeof(maxJ_)/sizeof(*maxJ_)); 
	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};
	  vector <int> minB(minB_, minB_+sizeof(minB_)/sizeof(*minB_)); 
	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};
	  vector <int> maxB(maxB_, maxB_+sizeof(maxB_)/sizeof(*maxB_)); 
	int k = 40; 
	double _ = -1; 
END

}
// END CUT HERE