题目标签是最短路?一开始没明白必须直接走是什么意思?好吧,是我脑残。
按时间排序之后,傻逼dp
f[i]=max{f[j]+1} (t[j]+a[j][i]<=t[i])
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #define maxn 410 using namespace std; struct yts { int x,id; }a[maxn]; int t[maxn][maxn]; int f[maxn]; int n,m,ans; bool cmp(yts x,yts y) { return x.x<y.x; } int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d",&a[i].x); a[i].id=i; } for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%d",&t[i][j]); sort(a+1,a+n+1,cmp); for (int i=1;i<=n;i++) { if (t[1][a[i].id]<=a[i].x) f[i]=1; for (int j=1;j<=i-1;j++) if (a[j].x+t[a[j].id][a[i].id]<=a[i].x) f[i]=max(f[i],f[j]+1); ans=max(ans,f[i]); } printf("%d\n",ans); return 0; }