标签:dp
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9399 | Accepted: 3025 |
Description
Input
Output
Sample Input
1 3 8 17 20 0 10 8 0 10 13 4 14 3
Sample Output
23
Source
POJ Monthly--2004.05.15 CEOI 2000
注意 [-10,10],[10,20],这两个平台在高度允许的情况下是可以跳的。。。。被坑了好久
#include <iostream> #include <fstream> #include <string> #include <time.h> #include <vector> #include <map> #include <queue> #include <algorithm> #include <stack> #include <cstring> #include <cmath> #include <set> #include <vector> using namespace std; #define INF 0x7fffffff int n,x,y,maxn; int dp[1111][2];//dp[i][0]表示到达i平台左端点最小值,dp[i][1]表示右端点最小值 bool vist[1111][2]; struct node{ int l; int r; int h; }dian[1111]; int cmp(const node &a,const node &b){ return a.h>b.h; } int main() { // freopen("G://test.txt","r",stdin); int t; scanf("%d",&t); while(t--){ scanf("%d%d%d%d",&n,&x,&y,&maxn); memset(vist,false,sizeof(vist)); dian[0].l=x; dian[0].r=x; dian[0].h=y; dp[0][0]=0; dp[0][1]=0; for(int i=1;i<=n;++i){ scanf("%d%d%d",&dian[i].l,&dian[i].r,&dian[i].h); dp[i][0]=dp[i][1]=INF; } sort(dian+1,dian+n+1,cmp); for(int i=1;i<=n;++i){ for(int j=0;j<i;++j){//枚举比i高的或者相等的(相等的下面if给T掉了) if(vist[j][0]==false){ if(dian[j].h>dian[i].h&&dian[j].h-dian[i].h<=maxn&&dian[j].l>=dian[i].l&&dian[j].l<=dian[i].r){ vist[j][0]=true; if(dp[j][0]==INF) continue; dp[i][0]=min(dp[i][0],dp[j][0]+dian[j].l-dian[i].l); dp[i][1]=min(dp[i][1],dp[j][0]+dian[i].r-dian[j].l); } }//左边 if(vist[j][1]==false){ if(dian[j].h>dian[i].h&&dian[j].h-dian[i].h<=maxn&&dian[j].r>=dian[i].l&&dian[j].r<=dian[i].r){ vist[j][1]=true; if(dp[j][1]==INF) continue; dp[i][0]=min(dp[i][0],dp[j][1]+dian[j].r-dian[i].l); dp[i][1]=min(dp[i][1],dp[j][1]+dian[i].r-dian[j].r); } }//右边 }//for }//for int ans=INF; for(int i=0;i<=n;++i){ if(vist[i][0]==false&&dian[i].h<=maxn) ans=min(ans,dp[i][0]); if(vist[i][1]==false&&dian[i].h<=maxn) ans=min(ans,dp[i][1]); } if(ans==INF){ printf("大兄弟。。。大于等于这个边界我也是跪了\n"); } else printf("%d\n",ans+y); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:dp
原文地址:http://blog.csdn.net/classicshao/article/details/47184753