用朴素的广搜尝试了一下,求大佬看看啥问题,只ac了5个点

P1434 [SHOI2002] 滑雪

hinadesu @ 2022-04-30 15:15:04

#include<bits/stdc++.h>
using namespace std;
int xx[]={0,-1,0,1};
int yy[]={1,0,-1,0};
int mp[105][105],a[105][105],vis[105][105];
int r,c,temp,maxx,maxy,ans;
int main(){
    cin>>r>>c;
    for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++){
            cin>>mp[i][j];
            if(mp[i][j]>temp){
                temp=mp[i][j];
                maxx=i;
                maxy=j;
            }
        }           
    queue< int >step;
    queue< int > a;
    queue< int > b;
    step.push(1);
    a.push(maxx);
    b.push(maxy);
    while(!step.empty()){
        for(int i=0;i<4;i++){
            int dx=a.front()+xx[i];
            int dy=b.front()+yy[i];
            if(dx>=1&&dx<=r&&dy>=1&&dy<=c&&(mp[dx][dy]<mp[a.front()][b.front()])){
                a.push(dx);
                b.push(dy);
                step.push(step.front()+1);
                ans=max(ans,step.front());              
            }               
        }
            a.pop();
            b.pop();
            step.pop(); 

}
    cout<<ans+1<<endl;
    return 0;   
}

by JQKLUMARKAR @ 2022-04-30 15:16:57

贪心策略有问题(?


by JQKLUMARKAR @ 2022-04-30 15:17:52

dp罢


|