【刷题】【记忆化搜索】【dp】Longtail Hedgehog
太巧的记忆化了,考虑到尾巴要求单调递增,且要求尾巴最长,则后者状态可由前者推导
https://codeforces.com/group/oqKDf9Vyex/contest/349763/problem/D
#include<cstdio> #include<cstdlib> #include<vector> #include<iostream> using namespace std; #define ll long long int n,m; const int N=1e5+10; vector <int > g[N]; ll f[N],ans;//ans=len(tail)*(g[end].size()-1) int main() { cin>>n>>m; while(m--) { int u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } f[1]=1,ans=g[1].size() ; for(int i=2;i<=n;i++) { f[i]=1; int sz=g[i].size() ; for(int j=0;j<sz;j++) if(g[i][j] < i ) f[i]=max(f[i],f[g[i][j] ]+1); ans=max(ans,f[i]*sz ); } cout<<ans; return 0; }