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 |
why wrong//自底向上 #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator