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

why wrong

Posted by 8128539 at 2009-04-05 20:56:50 on Problem 1644
//自底向上
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
__int64 dp[45][55];
int board[55];                       //a linear sequence of squares
int t;
int m,n;
const int MAX=0X7FFFFFFF;
void init()
{
	memset(dp,0,sizeof(dp));
	memset(board,0,sizeof(board));
}
void Read()
{
	int i,j;
	char c;
	scanf("%d %d",&m,&n);
	getchar();
	for(i=1;i<=m;)
	{
		scanf("%c",&c);
		j=0;
		if(c==' ')
		{
			continue;
		}
		else if(c=='-')
		{
			while(scanf("%c",&c),(c>='0' && c<='9'))
			{
				j=j*10+c-'0';
			}
			board[i]=-j;
			i++;
		}
		else if(c=='+')
		{
			while(scanf("%c",&c),(c>='0' && c<='9'))
			{
				j=j*10+c-'0';
			}
			board[i]=j;
			i++;
		}
		else if(c=='0')
		{
			board[i]=0;
			i++;
		}
		else if(c=='L')
		{
			board[i]=MAX;
			i++;
		}
	}
}
void dyna()
{
	int i,j;
	dp[0][0]=1;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=m-1;j++)
		{
			if(board[j+1]==MAX)
			{
				dp[i+1][j+1]+=dp[i-1][j];
			}
			else
			{
				dp[i][j+1+board[j+1]]+=dp[i-1][j];
			}
			if(board[j+2]==MAX)
			{
				dp[i+1][j+2]+=dp[i-1][j];
			}
			else
			{
				dp[i][j+2+board[j+2]]+=dp[i-1][j];
			}
		}
		dp[i][m+1]+=dp[i-1][m]*2+dp[i-1][m+1]*2;
	}
}
void print()
{
	int sum=0;
	double result;
	for(int i=0;i<=m+1;i++)
	{
		sum+=dp[n][i];
	}
	result=dp[n][m+1]/(sum*1.0);
		if(result>0.5)
			printf("Bet for. ");
		else if(result<0.5)
			printf("Bet against. ");
		else 
			printf("Push. ");
		printf("%0.4lf\n",result);
}
int main()
{
	scanf("%d",&t);
	while(t--!=0)
	{
		init();
		Read();
		dyna();
		print();
		for(int i=0;i<=52;i++)
		{
			printf("%I64d     ",dp[n][i]);
		}
		printf("\n");
	}
	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