题意很简单,给你n个严格上升的数字ai,
然后你要求出最大的子序列,满足相邻的数字不互质
我的思路比较奇葩,首先唯一分解每个ai,
然后通过他的质因子来寻找可能出现的转移的地方,然后dp[i] = max(dp[i], dp[k] + 1)
如果直接这样做会tle,然后我们想想,最靠前的边价值越小,不带转移的必要,所以我估算了下概率,舍掉80%的边直接不转移,然后就过了。。
//
// Created by Matrix on 2016-01-22
// Copyright (c) 2015 Matrix. All rights reserved.
//
//
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <sstream>
#include <set>
#include <vector>
#include <stack>
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x,begin())
#define ll long long
#define CLR(x) memset(x, 0, sizeof x)
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
const int maxv = 1e3 + 10;
const double eps = 1e-9;
int n;
int a[maxn];
vector <int> G[maxn];
int dp[maxn];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif
while(scanf("%d", &n) != EOF) {
for(int i = 1; i <= 1e5; i++)
G[i].clear();
CLR(dp);
int ans = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
dp[i] = 1;
vector <int> factors;
int k = a[i];
int num = sqrt(a[i] + 0.5);
for(int j = 2; j <= num; j++) {
if(k % j == 0) {
factors.push_back(j);
while(k % j == 0) {
k /= j;
}
}
if(k == 1) break;
}
if(k != 1) factors.push_back(k);
for(k = 0; k < factors.size(); k++) {
num = factors[k];
int up = G[num].size();
up = up * 0.8;
for(int j = G[num].size() - 1; j >= up; j--) {
dp[i] = max(dp[i], dp[G[num][j]] + 1);
}
}
for(k = 0; k < factors.size(); k++) {
num = factors[k];
G[num].push_back(i);
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
return 0;
}