Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
可耻的贴代码#include <iostream> #include <memory.h> #include <cstdio> using namespace std; float p[3][160];//每次算完第i行,就把第i-1行换掉 int C,N,M;//c:颜色数,N:总共拿球次数,M:最后剩下颜色数 float findre() { memset(p,0,sizeof(p)); p[0][0]=1; for(int i=1;i<=N;i++) { for(int j=0;j<=C+1;j++) { p[i%2][j]=p[(i-1)%2][j-1]*(C-j+1)/C; p[i%2][j]+=p[(i-1)%2][j+1]*(j+1)/C; } for(int j=0;j<=C+1;j++) { p[(i-1)%2][j]=p[i%2][j]; } } return p[N%2][M]; } int main() { cin>>C; while(C!=0) { cin>>N>>M; if(N>1000) N=1000+N%2; float result; if(M>C) result=0; else result=findre(); printf("%.3f\n",result); cin>>C; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator