Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
142269 吴悠 滑雪 C++ 通过 100 0 MS 276 KB 926 2024-04-06 20:04:31

Tests(5/5):


#include<iostream> #include<algorithm> using namespace std; int a[101][101],dp[101][101]; int dx[4]={0,0,-1,1}; int dy[4]={1,-1,0,0}; struct Node{ int h; int x; int y; }node[10001]; bool cmp(Node a,Node b){ return a.h<b.h; } int main(){ int r,c; cin>>r>>c; for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ cin>>a[i][j]; node[(i-1)*c+j].h=a[i][j]; node[(i-1)*c+j].x=i; node[(i-1)*c+j].y=j; } } sort(node+1,node+r*c+1,cmp); for(int i=1;i<=r*c;i++){ int nx=node[i].x; int ny=node[i].y; int max_=0; for(int j=0;j<4;j++){ int xx=nx+dx[j]; int yy=ny+dy[j]; if((xx>=1 && xx<=r) && (yy>=1 && yy<=c)){ if(a[xx][yy]<node[i].h){ max_=max(max_,dp[xx][yy]); } } } dp[nx][ny]=max_+1; } int ans=0; for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ if(dp[i][j]>ans){ ans=dp[i][j]; } } } cout<<ans<<endl; return 0; }


测评信息: