# BZOJ 1663: [Usaco2006 Open]赶集 floyd（划掉+dp

bzoj1663

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <cstring>
#include <ctime>
#include <vector>
#define inf 1e9
#define ll long long
#define maxn 20010
#define For(i,j,k) for(ll i=j;i<=k;i++)
#define Dow(i,j,k) for(ll i=k;i>=j;i--)
using namespace std;
inline void read(int &tx){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  tx=x*f; }
inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  }
inline void writeln(ll x){write(x);puts("");}
int n,ans,f[1001][1001],dp[1001];
int main()
{
sort(g+1,g+n+1,cmp);
For(i,1,n)
{
if(f[1][g[i].p]<=g[i].t)	dp[i]=1;
For(j,1,i-1)
{
if(f[g[j].p][g[i].p]<=g[i].t-g[j].t)
dp[i]=max(dp[i],dp[j]+1);
}
ans=max(ans,dp[i]);
}
writeln(ans);
}


11-20 505

10-09 869
02-11 507
08-10 54
03-15 581
02-26 242
03-17 1692
10-25 46
02-27 336
02-08 157
03-31 151