codeforces 264B
来源:互联网 发布:淘宝网上假发 编辑:程序博客网 时间:2024/05/16 05:41
题意很简单,给你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;}
0 0
- codeforces 264B
- Codeforces 264B (Good Sequences)
- Good Sequences(codeforces 264B)
- codeforces 264B Good Sequences
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- codeforces 264B B. Good Sequences(dp+数论)
- codeforces 264b Good Sequences dp
- Codeforces Round #264 (Div. 2) B
- codeforces Round #264(div2) B解题报告
- codeforces #264B Good Sequences (dp)
- CodeForces 264B Good Sequences dp
- Codeforces 264B Good Sequences (dp)
- Codeforces 264B Good Sequences【dp+思维】
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- leetcode第17题——**Letter Combinations of a Phone Number
- 欢迎使用CSDN-markdown编辑器
- 1204 寻找子串位置
- cvResize() 图像放缩
- 三种弹窗的解析
- codeforces 264B
- What are bitwise operators?
- String、StringBuffer和StringBuilder类
- innerHTML和innerText造成的乱码现象 以及 background-image放入.css中失效
- 蓝桥杯 日期计算
- Java集合(实现类线程安全性)
- codeforces 258B
- 值得 Web 开发人员学习的20个 jQuery 实例教程
- akira的android豆知识160122