Artifact 70b68db021e8c302b347247659fa9b7d516f316f
#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;
LL comb(LL n, LL k)
{
k = min(k, n-k);
LL c = 1;
for(LL i=0; i<k; ++i)
c *= n-i, c /= i+1;
return c;
}
class TheQuestionsAndAnswersDivOne { public:
int find(int questions, vector <string> answers)
{
int Y = count(answers.begin(), answers.end(), string("Yes"));
int N = count(answers.begin(), answers.end(), string( "No"));
int cnt = 0;
for(int y=0; y<=questions; ++y)
{
int n = questions - y;
if( y<=Y && n<=N )
cnt += distr(Y,y)*distr(N,n)*comb(questions, y);
}
return cnt;
}
int distr(int n, int k)
{
if( k <= 1 )
return (k==1 || n==0&&k==0) ? 1 : 0;
int sum = 0;
for(int m=1; m<(1<<n); ++m) {
int pop = 0;
for(int i=1; i<=m; i<<=1)
if(m&i)
++pop;
if( n-pop >= k-1 )
sum += distr(n-pop, k-1);
}
return sum;
}
};
// 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(_, TheQuestionsAndAnswersDivOne().find(questions, answers));}
int main(){
CASE(0)
int questions = 2;
string answers_[] = {"No", "Yes"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 2;
END
CASE(1)
int questions = 2;
string answers_[] = {"No", "No", "No"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 6;
END
CASE(2)
int questions = 3;
string answers_[] = {"Yes", "No", "No", "Yes"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 12;
END
CASE(3)
int questions = 3;
string answers_[] = {"Yes", "Yes", "Yes", "No"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 18;
END
CASE(4)
int questions = 2;
string answers_[] = {"Yes","Yes"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 2;
END
CASE(4)
int questions = 2;
string answers_[] = {"No","No"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 2;
END
CASE(4)
int questions = 2;
string answers_[] = {"Yes","No"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 2;
END
CASE(5)
int questions = 7;
string answers_[] = {"Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"};
vector <string> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_));
int _ = 40320*9;
END
}
// END CUT HERE