Orac and Model(最长上升子序列)

题目链接: Orac and Models


大致题意:

给出n个数的值,求出满足下标j整除i并且a[j]>a[i]的最多个数(j>i)


解题思路:

最长上升子序列的变形

转移方程:f[j]=max(f[j],f[i]+1)


AC代码:

#include 
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int n;
int a[N];
int f[N];
int main() {
	int t; cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; ++i)cin >> a[i];
		for (int i = 0; i <= n; ++i)f[i] = 1;
		for (int i = 1; i <= n; ++i)
			for (int j = 2 * i; j <= n; j += i)
				if (a[i] < a[j])f[j] = max(f[j], f[i] + 1);
		int res = 0;
		for (int i = 1; i <= n; ++i)res = max(res, f[i]);
		cout << res << endl;
	}
	return 0;
}

END

你可能感兴趣的:(动态规划,动态规划,算法)