//TCoverUp.cc //ecna 2009 //problem B - Cover Up #include #include using namespace std; //for debugging void PrintVectors(int n, int A[], double B[], int C[], double D[]){ cout<<"n="<0.999999999999) cout<<1<=.499999999999) n++; if(n%100 ==0) cout< Likely, Choice[]==1 => UnLikely // hits[]==1 => correct // must have at least one correct P1 = 1.0; //P1 = prob of that combo of hits for(int i=0;i we picked UnLikely if(UnLikelyProb[i]==0.0) P1 = 0.0; else P1 *= UnLikelyProb[i]/UnLikelyNum[i]; } } else { //hits[i]==0 => we picked digit i wrong if(Choice[i]==0){ //we picked likely if(LikelyProb[i]==0.0) //of course we're wrong P1 *= 1.0; else{ if(LikelyNum[i]<=1) P1 *= UnLikelyProb[i]; //must be an unlikely else P1 *= (LikelyProb[i]*(LikelyNum[i]-1)/LikelyNum[i]) + UnLikelyProb[i]; } } else { //Choice[i]==1 => we picked an unlikely if(UnLikelyProb[i]==0.0) P1 *= 1.0; else if (UnLikelyNum[i]<=1) P1 *= LikelyProb[i]; else P1 *= (UnLikelyProb[i]*(UnLikelyNum[i]-1)/UnLikelyNum[i]) + LikelyProb[i]; } } } // end for i // P1 now = prob we get those hits //now calculate ProbOfSuccess for remaining incorrect digits P2 = 1.0; if(P1>0){ int j = -1; // j = # of wrong digits - 1 for(int i=0;i0) NewUnLikelyProb[j] = 1.0; else NewUnLikelyProb[j]=0.0; } else { // still more Likely's to pick if(Pwrong==0) { // for error checking - this shouldn't happen cout <<"Pwrong is 0 (Likely "< we picked an Unlikely Pwrong = 1 - UnLikelyProb[i]/UnLikelyNum[i]; //cout<<"calculate Pwrong: "<0) NewLikelyProb[j] = 1.0; else NewLikelyProb[j] = 0.0; } else { // still more UnLikely's if(Pwrong==0) { // for error checking - this shouldn't happen cout <<"Pwrong is 0 (Unlikely "<< i<<") "; PrintVectors(n, LikelyNum, LikelyProb, UnLikelyNum, UnLikelyProb); } NewUnLikelyNum[j] = UnLikelyNum[i] - 1; NewUnLikelyProb[j] = (UnLikelyProb[i]/UnLikelyNum[i])/Pwrong*(UnLikelyNum[i]-1); NewLikelyNum[j] = LikelyNum[i]; NewLikelyProb[j] = LikelyProb[i]/Pwrong; } } } // end if } // end for i P2 = ProbOfSuccess(j+1, NewLikelyNum, NewLikelyProb, NewUnLikelyNum, NewUnLikelyProb); } } // end for k if(Prob>1.0){ // for error checking - this shouldn't happen cout<<" **** prob too hi "<0) P = LikelyProb[0]/LikelyNum[0]; if (UnLikelyNum[0]>0) if (UnLikelyProb[0]/UnLikelyNum[0]>P) P = UnLikelyProb[0]/UnLikelyNum[0]; // return P; } else //else n>1 for(int i=0;i Likely, Choice[]=1 => UnLikely //only calculate prob if Choice[] can have at least one right OK = true; for(int j=0;j>n; while(n>0){ for(int i =0; i>m>>l>>p; LikelyNum[i] = l; UnLikelyNum[i] = m - l; LikelyProb[i] = p; UnLikelyProb[i] = 1.0 - p; } Prob = ProbOfSuccess(n, LikelyNum, LikelyProb, UnLikelyNum, UnLikelyProb); Print(Prob); cin>>n; } return 0; }