1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include<bits/stdc++.h> using namespace std; const int max_n=15,max_m=102,inf=1000000009; inline int read(){ int x=0;bool w=0;char c=getchar(); while(c<'0' || c>'9') w|=c=='-',c=getchar(); while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return w?-x:x; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); }
int n,m,S; int f[1<<14][max_m],g[1<<14][max_m];
struct Key{ int x,y,t; Key(){t=0;} bool operator < (const Key &b) const{ Key a=*this; return a.t<b.t; } }a[max_n],b[max_m];
inline int Dis(Key a,Key b){ return abs(b.y-a.y)+abs(b.x-a.x); }
int ptt[1<<14][max_m],ptp[1<<14][max_n];
signed main(){ n=read(),m=read(),S=(1<<n); memset(f,0x3f,sizeof(f)),memset(g,0xaf,sizeof(g)); memset(ptt,0x3f,sizeof(ptt)),memset(ptp,0x3f,sizeof(ptp));
for(register int i=0;i<n;++i) a[i].x=read(),a[i].y=read(); for(register int i=1;i<=m;++i) b[i].x=read(),b[i].y=read(),b[i].t=read(); sort(b+1,b+1+m);
for(register int s=0;s<S;++s) for(register int i=0;i<n;++i) if((s>>i)&1){ for(register int j=1;j<=m;++j) ptt[s][j]=min(ptt[s][j],Dis(a[i],b[j])); for(register int j=0;j<n;++j) ptp[s][j]=min(ptp[s][j],Dis(a[i],a[j])); } for(register int i=0;i<n;++i) f[1<<i][0]=0; for(register int i=1;i<=m;++i) g[0][i]=1; for(register int s=0;s<S;++s){ for(register int i=0;i<=m;++i){ if(f[s][i]>inf) continue; for(register int j=1;j<=m;++j) if(f[s][i]+ptt[s][j]<=b[j].t) g[s][j]=max(g[s][j],i+1); for(register int j=0;j<n;++j) if(!((s>>j)&1)) f[s|(1<<j)][i]=min(f[s|(1<<j)][i],f[s][i]+ptp[s][j]); } for(register int i=1;i<=m;++i){ if(g[s][i]<-inf) continue; for(register int j=i+1;j<=m;++j) if(b[i].t+min(Dis(b[i],b[j]),ptt[s][j])<=b[j].t) g[s][j]=max(g[s][j],g[s][i]+1); for(register int j=0;j<n;++j) f[s|(1<<j)][g[s][i]]=min(f[s|(1<<j)][g[s][i]],b[i].t+min(Dis(b[i],a[j]),ptp[s][j])); } } int ans=0; for(register int s=0;s<S;++s) for(register int j=1;j<=m;++j) ans=max(ans,g[s][j]); write(ans); return 0; }
|