nssl1446-小智的旅行【dp】
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                nssl1446-小智的旅行【dp】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                正題
題目大意
求一條最大的權值嚴格上升的路徑。
解題思路
將邊權排序,然后從fxf_xfx?轉移到fy+1f_y+1fy?+1即可,要注意的是因為嚴格上升,所以此次轉移用的fff不能是相同權值轉移時轉移的。
codecodecode
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int N=5e5+10; struct node{int x,y,w; }a[N]; queue<pair<int,int> > q; int n,m,f[N],ans; bool cmp(node x,node y) {return x.w<y.w;} int main() {scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);a[i].x++;a[i].y++;}sort(a+1,a+1+m,cmp);for(int i=1;i<=m;i++){if(a[i].w!=a[i-1].w){while(!q.empty()){int x=q.front().first,w=q.front().second;f[x]=max(f[x],w);q.pop();}}q.push(make_pair(a[i].y,f[a[i].x]+1));q.push(make_pair(a[i].x,f[a[i].y]+1));}while(!q.empty()){int x=q.front().first,w=q.front().second;f[x]=max(f[x],w);q.pop();}for(int i=1;i<=n;i++)ans=max(ans,f[i]);printf("%d",ans); } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的nssl1446-小智的旅行【dp】的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 古代亭长是什么官
 - 下一篇: nssl1447-小智的糖果【dp】