poj1699Best Sequence(TSP)

题目链接:点这里!!!


题解:

我们直接求出两两之间的公共部分是多少,然后直接跑TSP就ok了,但是有个梗,我们要事先对字符串按长度排好序,尽可能去匹配长的,就可以了!!!!

给组数据:

/*

5
aaaaaaa
a
aa
aaa
aaaaab

*/



代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pb push_back
#define pa pair
#define clr(a,b) memset(a,b,sizeof(a))
#define lson lr<<1,l,mid
#define rson lr<<1|1,mid+1,r
#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x)
#define key_value ch[ch[root][1]][0]
#pragma comment(linker, "/STACK:102400000000,102400000000")
typedef  long long LL;
const LL  MOD = 1000000007;
const int N = 55;
const int maxn = 1e6+15;
const int letter = 130;
const int INF = 1e9;
const double pi=acos(-1.0);
const double eps=1e-10;
using namespace std;
inline int read()
{
    int 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();}
    return x*f;
}
int n;
int mp[25][25],a[25];
int dp[1<<15][25];
struct node{
    char s[25];
    bool operator < (const node &p) const{
        int n=strlen(s),m=strlen(p.s);
        return nm;
}
int check(char a[],char b[]){
    int n=strlen(a),m=strlen(b);
    int vs=0;
    for(int i=0;i


你可能感兴趣的:(图论,旅行商问题(TSP))