标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1418 Accepted Submission(s): 471
#include <stdio.h> #include <iostream> #include <string.h> #include <math.h> #include <algorithm> using namespace std; const int M = 10005; struct grid{ int t,r,c; }g[M]; int dp[M]; int cmp(grid a,grid b){ return a.t < b.t; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF,n+m){ for(int i=1;i<=m;i++){ scanf("%d%d%d",&g[i].t,&g[i].r,&g[i].c); } sort(g+1,g+m+1,cmp); int ans = -1; for(int i=1;i<=m;i++){ dp[i]=1; for(int j=1;j<i;j++){ int usetime = abs(g[i].r-g[j].r)+abs(g[i].c-g[j].c); if(usetime<=abs(g[j].t-g[i].t)&&dp[j]+1>dp[i]) dp[i] = dp[j]+1; } ans = max(ans,dp[i]); } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5379077.html