求大神指导

P1514 [NOIP2010 提高组] 引水入城

我跟你一样也40分过,找不出错误 求大神指导谢谢 #include<iostream> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int n,a[5100][5100],num1,num2,m,ans1=0,ans2=0,l=0; bool used[5100][5100]={false},flag=false,flag1=true; int c[5]={0,1,-1,0,0},d[5]={0,0,0,1,-1}; struct node{ int h,numm; }b[5100]; bool cmp(node xx , node yy){ return xx.h>yy.h; } void dfs(int x,int y){//x,y是在(x,y)建蓄水厂 now是已经覆盖到的干旱区的数量 if(x==n) l++; if(l==m){ flag=true; return ; } if(y+1<=m&&used[x][y+1]==true&&a[x][y+1]<a[x][y]){ used[x][y+1]=false; dfs(x,y+1); } if(y-1>0&&used[x][y-1]==true&&a[x][y-1]<a[x][y]){ used[x][y-1]=false; dfs(x,y-1); } if(x+1<=n&&used[x+1][y]==true&&a[x+1][y]<a[x][y]){ used[x+1][y]=false; dfs(x+1,y); } if(x-1>0&&used[x-1][y]==true&&a[x-1][y]<a[x][y]){ used[x-1][y]=false; dfs(x-1,y); } } int main(){ cin>>n>>m; for(int j=1;j<=m;j++){ cin>>b[j].h; b[j].numm=j; a[1][j]=b[j].h; used[1][j]=true; } sort(b+1,b+1+m,cmp); for(int i=2;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; used[i][j]=true; } } for(int i=1;i<=m;i++){ if(used[1][b[i].numm]==true){ ans1++; used[1][b[i].numm]=false; dfs(1,b[i].numm); } else{ continue; } if(flag){ cout<<1<<endl<<ans1; return 0; } } cout<<0<<endl<<(m-l); return 0; } 代码+解释 谢谢
by 四代火影 @ 2018-05-22 19:59:13


过了1,4,5,6四个点 找不出错误 求大神指导啊啊啊啊 谢谢! 贴
by 四代火影 @ 2018-05-22 19:59:55


|