标签:stream ref 滑雪 include ring ++ michael 整数 记忆化搜索
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 100636 | Accepted: 38304 |
Description
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Input
Output
Sample Input
5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Sample Output
25
Source
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; int r,c,ans,h[110][110],f[110][110]; int dp(int x,int y){ if(f[x][y]) return f[x][y]; int ans=0; for(int i=0;i<4;i++){ int cx=x+dx[i]; int cy=y+dy[i]; if(cx>0&&cx<=r&&cy>0&&cy<=c&&h[x][y]>h[cx][cy]){ ans=max(ans,dp(cx,cy)); } } f[x][y]=ans+1; return ans+1; } int main(){ scanf("%d%d",&r,&c); for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) scanf("%d",&h[i][j]); for(int i=1;i<=r;i++) for(int j=1;j<=c;j++){ f[i][j]=dp(i,j); ans=max(ans,f[i][j]); } printf("%d",ans); }
标签:stream ref 滑雪 include ring ++ michael 整数 记忆化搜索
原文地址:http://www.cnblogs.com/cangT-Tlan/p/7462433.html