Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大牛帮我看看,感激不尽,N次RE,快崩溃了

Posted by TurnAround at 2009-05-28 22:12:51 on Problem 1322
#include <iostream>
#include <iomanip>
using namespace std;

const int array_size = 1000;
const int most_color = 100;
double value[array_size+1][most_color+1] = {0};

int main()
{
	
	int C, N, M;
	
	while(cin >> C){
		if(C == 0){
			break;
		}
		cin >> N >> M;	
		if(M>C || M>N){
			cout << "0.000" << endl;
			continue;	
		}
	
		if(N > 1000){
			if(N%2 == 0){
				N = 1000;
			}else{
				N = 1001;
			}	
		}
	
		for(int i=0; i<=N; i++){
			for(int j=0; j<=C; j++){
				value[i][j] = 0;
			}
		}

		value[1][1] = 1;			
		for(int i=2; i<=N; i++){
			for(int j=0; j<=C; j++){
				if(j > i){
					break;	
				}
				
				if(j == C){
					value[i][C] = value[i-1][C-1]/C;
				}else if(j == 0){
					value[i][0] = value[i-1][1]/C;
				}else{
					value[i][j] = (value[i-1][j-1]*(C-j+1)/C +
						value[i-1][j+1]*(j+1)/C);
				}	
				
				if( i>=N && j>=M){
					break;
				}
			}
		}

		cout<<setiosflags(ios::fixed)<<setprecision(3)<<value[N][M]<<endl;
	}
	return 0;
}
		
				
		

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator