POJ 2138 最长路
来源:互联网 发布:彩票免费计划软件 编辑:程序博客网 时间:2024/06/05 23:53
思路:
如果j能由i得到 则i向j连一条边
答案就是最长路的末节点所代表的string
//By SiriusRen#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define N 3005int n,first[N],next[N*N],v[N*N],tot=1,t,head,tail=1,q[N*N];struct Node{char a[1088];int len;}str[1005];void add(int x,int y){v[tot]=y,next[tot]=first[x],first[x]=tot++;}int main(){ scanf("%d",&n); for(int i=0;i<=n;i++)scanf("%s",str[i].a),str[i].len=strlen(str[i].a); for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) if(str[i].len+1==str[j].len){ int tempa=0,tempb=str[j].len-1; while(str[i].a[tempa]==str[j].a[tempa])tempa++; while(str[i].a[tempb-1]==str[j].a[tempb])tempb--; if(tempa>=tempb)add(i,j); } while(head<tail){ t=q[head++]; for(int i=first[t];i;i=next[i])q[tail++]=v[i]; } printf("%s",str[t].a);}
0 0
- POJ 2138 最长路
- poj 1932(最长路Bellman_Ford
- POJ 1716(spfa最长路
- POJ 2631 最长路搜索,BFS
- poj 2485Highways (求最长路)
- poj 3249 Test for Job 最长路
- 【最长路】POJ 1860 Currency Exchange
- 【POJ】1949 Chores DAG最长路
- POJ 1201 差分约束、最长路
- poj 1860 Currency Exchange(最长路)
- poj 1383 Labyrinth (迷宫 最长路)
- poj 2240 最长路变形 Floyd改写
- poj 3160 强连通+最长路
- poj 1201(差分约束+最长路)
- DP LIS(最长上升子序列) POJ 2533 POJ 1836 POJ 2138 HDU 1069
- poj 3592 Instantaneous Transference tarjan缩点 最长路 ++tarjan模版 && spfa最长路模版
- POJ--3592[Instantaneous Transference] 缩点+求最长路
- HDU 1317 POJ 1932 XYZZY 正负环+最长路
- 检测是否为回文字符串 C++实现
- JavaScript中的参数传递方式
- 图像分割(Image Segmentation)
- C#-DUP
- android学习的小总结
- POJ 2138 最长路
- 2016.10.29
- C#-Socket(TCP)
- Java监听器
- 初入此坑,请多关照。
- 【书目推荐】你从未真正拼过
- C语言实现三子棋
- (译)LearnOpenGL实际案例Breakout(九):后期处理
- leetcode (11) - Container With Most Water