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 |
擦,我明白了,第一个下标没越界,后面两个越界了,囧啊。。。In Reply To:太诡异了,数组开dp[2][105][105]会RE,开dp[3][105][105]则AC,我保证数组下标没越界 Posted by:woLaiDaJiangYou at 2012-03-09 20:40:50 这个才是正确的代码: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; #define N 105 int w,h; char city[N][N]; int dp[2][N][N]; void DP() { int m,i,j,k,nsteps=w+h-2; if(city[0][0]=='*') dp[0][0][0]=1; else dp[0][0][0]=0; for(k=1;k<=nsteps;k++) { for(i=0;i<=k && i<h;i++) { if(k-i>=w) continue; for(j=0;j<=k && j<h;j++) { if(k-j>=w) continue; if(city[i][k-i]=='#' || city[j][k-j]=='#') { dp[1][i][j]=-1; continue; } m=-1; if(i<=k-1 && j<=k-1) m=max(m,dp[0][i][j]); if(j<=k-1 && i-1>=0) m=max(m,dp[0][i-1][j]); if(i<=k-1 && j-1>=0) m=max(m,dp[0][i][j-1]); if(i-1>=0 && j-1>=0) m=max(m,dp[0][i-1][j-1]); if(m==-1) { dp[1][i][j]=-1; continue; } dp[1][i][j]=m; if(city[i][k-i]=='*') dp[1][i][j]++; if(i!=j && city[j][k-j]=='*') dp[1][i][j]++; } } for(i=0;i<=k && i<h;i++) { if(k-i>=w) continue; for(j=0;j<=k && j<h;j++) { if(k-j>=w) continue; dp[0][i][j]=dp[1][i][j]; } } } } int main() { int cases,i; scanf("%d",&cases); while(cases--) { scanf("%d%d",&w,&h); for(i=0;i<h;i++) scanf("%s",city[i]); DP(); printf("%d\n",dp[1][h-1][h-1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator