JZOJ 3490. 旅游(travel)
题目大意
两个图,单调的跑
分析
- 暴力DP
代码
1 #pragma GCC optimize(2) 2 #pragma GCC optimize(3) 3 #include<bits/stdc++.h> 4 using namespace std; 5 struct sb 6 { 7 long long x,y,t,val; 8 }a[1000010]; 9 long long cnt=0; 10 long long read() { 11 long long res = 0; 12 char c = getchar(); 13 while(!isdigit(c)) c = getchar(); 14 while(isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar(); 15 return res; 16 } 17 bool cmp(sb a,sb b) 18 { 19 return a.val>b.val?true:false; 20 } 21 long long f[1000010]; 22 int mapp[1001][1001]; 23 int main () 24 { 25 long long n,m,x; 26 n=read(); m=read(); 27 for (int i=1;i<=n;i++) 28 for (int j=1;j<=m;j++) 29 mapp[i][j]=read(); 30 cnt=0; 31 for (int i=1;i<=n;i++) 32 for (int j=1;j<=m;j++) 33 { 34 x=read(); 35 if (mapp[i][j]==0&&x==0) continue; 36 a[++cnt].x=i; a[cnt].y=j; a[cnt].val=mapp[i][j]; a[cnt].t=x; 37 } 38 sort(a+1,a+1+cnt,cmp); 39 long long tot=1,j=1; 40 f[1]=a[1].t; 41 while (a[j].val==a[j+1].val) tot++,j++,f[j+1]=a[j+1].t; 42 long long ans=0; 43 long long l=1,r=tot,noww=a[tot+1].val; 44 for (int i=tot+1;i<=cnt;i++) 45 { 46 if (a[i].val!=a[r+1].val) 47 l=r+1,r=i-1; 48 for (int j=l;j<=r;j++) 49 f[i]=max(f[i],f[j]+abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y)+a[i].t); 50 ans=max(ans,f[i]); 51 } 52 cout<<ans; 53 }
为何要逼自己长大,去闯不该闯的荒唐