【DP】51Nod 1274 最长递增路径
来源:互联网 发布:淘宝店在那搞活动 编辑:程序博客网 时间:2024/05/22 10:42
题面在这里
好题啊……
肯定会有这样的DP:
然而就算离散后还是
其实可以直接对边排序,边权的那一维就可以省去了
Tips:以后遇到边权递增的题目,第一想到对边排序
值得注意的是,边权相同的边必须同时转移,不能有先后修正的关系
示例程序:
#include<cstdio>#include<algorithm>using namespace std;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline int red(){ int res=0,f=1;char ch=nc(); while (ch<'0'||'9'<ch) {if (ch=='-') f=-f;ch=nc();} while ('0'<=ch&&ch<='9') res=res*10+ch-48,ch=nc(); return res*f;}const int maxn=50005;int n,e,f[maxn];struct edge{ int x,y,w; bool operator<(const edge&b)const{ return w<b.w; }}a[maxn];struct data{ int x,i; data () {} data (int _i,int _x):i(_i),x(_x) {}}q[maxn];int main(){ n=red(),e=red(); for (int i=1;i<=e;i++) a[i].x=red()+1,a[i].y=red()+1,a[i].w=red(); sort(a+1,a+1+e); for (int i=1;i<=e;){ int j=i,len=0; while (j<=e&&a[j].w==a[i].w){ q[++len]=data(a[j].x,f[a[j].y]+1); q[++len]=data(a[j].y,f[a[j].x]+1); j++; } i=j; for (j=1;j<=len;j++) f[q[j].i]=max(f[q[j].i],q[j].x); } int ans=0; for (int i=1;i<=n;i++) ans=max(ans,f[i]); printf("%d",ans); return 0;}
阅读全文
1 0
- 51nod 1274 最长递增路径【dp】
- 51nod 1274 最长递增路径(dp)
- 【DP】51Nod 1274 最长递增路径
- 51nod 1274 最长递增路径【DP】
- 51nod 1274 最长递增路径[dp]
- 51nod 1274 最长递增路径(图上的dp)
- [DP] 51 Nod 1274——最长递增路径
- 51NOD 1274 最长递增路径
- 51nod-1274 最长递增路径
- 51nod 1274 最长递增路径
- 51Nod-1274-最长递增路径
- 51NOd 1134 最长递增子序列(dp)
- 51nod 1134 最长递增子序列(dp)
- 51nod 1134 最长递增子序列 dp(经典)
- 51nod 1218 最长递增子序列 V2 [dp]
- 51nod 1134 最长递增子序列 DP
- Lcs最长递增 51nod
- 最长公共子序列 + 记录路径 ( 51 NOD DP 教程 )
- I Love the World!
- surf三维画图[matlab]
- 微信域名检测接口服务器环境配置文档
- Stack (30)
- [iOS]setValue和setObject区别
- 【DP】51Nod 1274 最长递增路径
- Python 豆瓣影评抓取
- C++中四种类型转换方式
- 社团检测(Community Detection)和聚类(Clustering)
- 【C++】PCH 警告:标头停止点不能位于宏或#if块中
- SlidingMenu的使用
- Eclipse的WorkingSet使用
- 如何更新npm版本
- LightOj-1022-Circle in Square