其他分享
首页 > 其他分享> > 102最长因子链

102最长因子链

作者:互联网

 

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define fi first
 4 #define se second
 5 #define go continue
 6 #define woc puts("");
 7 #define int long long
 8 #define PII pair<int, int>
 9 #define sf(x) scanf("%lld",&x)
10 #define ytz int _; sf(_); while(_--)
11 #define fory(i,a,b) for(int i = a; i <= b; ++i)
12 #define forl(i,a,b) for(int i = a; i >= b; --i)
13 #define debug(a) cout << #a << " = " << a <<endl;
14 const int N = 1010;
15 int n;
16 int a[N], f[N];
17 signed main()
18 {
19     sf(n);
20     fory(i, 1, n) sf(a[i]), f[i] = 1;
21     sort(a + 1, a + 1 + n);
22     fory(i, 1, n)
23     {
24         fory(j, i + 1, n)
25         {
26             if(a[j] % a[i] == 0) f[j] = max(f[j], f[i] + 1);
27         }
28     }
29     int ans = -1e18;
30     fory(i, 1, n) ans = max(ans, f[i]);
31     printf("%lld", ans);
32     return 0;
33 }

 

标签:cout,int,long,sf,因子,102,最长,define
来源: https://www.cnblogs.com/-ytz/p/15959191.html