http://acm.zznu.edu.cn/problem.php?id=1964
Title Description
Input
Output
Sample input
22 10 11 03 10 1 11 0 11 1 0
Sample output
0.5001.125
Tips
Before thinking of a formula is 0.5*pow (0.5,k) *c (k,n);
K is at least recognize K personal n is to know n person
And then all the teammates wrote out everything, and I just went to verify that the second test data was wrong. I really wanted to jump out of the five upstairs.
The correct formula should be
for (i=k;i<=n;i++)
{
Ans+=0.5*pow (0.5,n) *c (i,n);
}
It makes sense to think about it.
Why was he blinded?
#include <iostream>#include<cstring>#include<algorithm>#include<queue>#include<cstdio>#include<cstdlib>#include<cctype>#include<cmath>using namespacestd;intnum[ -];intx1[ -];intx2[ -];ints[ -][ -];voidInit (intN) {memset (s),0,sizeof(s)); for(intI=1; i<=n; i++) { intx=i; for(intj=2; j<=i; J + +) { if(x%j==0) {S[i][j]++; X/=J; J--; } } }}Long LongCintNintk) {memset (x1,0,sizeof(x1)); memset (x2,0,sizeof(x2)); for(intI=2; i<=k; i++) { for(intj=2; j<=i; J + +) {X1[j]+=S[i][j]; } } for(inti=n-k+1; i<=n; i++) { for(intj=2; j<=i; J + +) {X2[j]+=S[i][j]; } } for(intI=2; i<= -; i++) {X2[i]-=X1[i]; } Long Longans=1; for(intI=2; i<= -; i++) { for(intj=1; j<=x2[i];j++) {ans*=i; } } returnans;}DoubleSolveintNintk) { Doubleans=0; for(inti=k;i<=n;i++) {ans+=0.5*c (n, i) *pow (0.5, N); } returnans;}intMain () {intT; intN, K; intx; scanf ("%d", &t); Init ( -); while(t--) {scanf ("%d%d", &n, &k); for(intI=1; i<=n; i++) { intsum1=0; for(intj=1; j<=n; J + +) {scanf ("%d", &x); if(x==1) sum1++; } Num[i]=sum1; } Doubleans=0; for(intI=1; i<=n; i++) { if(num[i]>=k) {ans+=solve (num[i],k); }} printf ("%.3lf\n", ans); } return 0;}
2015 Light College race D Social network (permutation combination)