1 solutions

  • 1
    @ 2022-1-6 18:40:50
    #include<iostream>
    using namespace std;
    int n,m,s,ans=0;
    int ma[110][110];
    int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
    //传参的sum就是到(x,y)时经过的路径数字总和
    void dfs(int x,int y,int sum){
    	ans=max(ans,sum);
    	for(int i=0;i<4;i++){
    		int xx=x+dx[i];
    		int yy=y+dy[i];
    		if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&ma[xx][yy]>ma[x][y])
    			dfs(xx,yy,sum+ma[xx][yy]);
    	}
    }
    int main() {
    	cin>>n>>m>>s;
        //通过题目所给的算法建好地图
    	for(int i=1;i<=n;i++)
    		for(int j=1;j<=m;j++){
    			s=(s*345)%19997;
    			ma[i][j]=s%10+1;
    		}
        //把每个点都作为起点开始搜索
    	for(int i=1;i<=n;i++)
    		for(int j=1;j<=m;j++)
    			dfs(i,j,ma[i][j]);
    	cout<<ans<<endl;
    	return 0;
    }
    
    • 1

    Information

    ID
    718
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    4
    Tags
    # Submissions
    95
    Accepted
    46
    Uploaded By