题目:http://codeforces.com/problemset/problem/264/B

题意:给你一个递增序列,然后找出满足两点要求的最长子序列

第一点是a[i]>a[i-1]

第二点 gcd(a[i],a[i-1])>1 也就是说两个数不能互质

找出最长的子序列长度

思路:首先想互质问题,如果两个数互质说明两个数之间没有素因子相同,我们想以每个素因子结尾的最大长度是多少

然后比如样例 2 3 4 6 9

第一个数 2      2结尾 1

第二个数 3      3结尾 1

第三个数 4       2结尾 2

第四个数6        拆分因子有   2,3      2结尾 3, 3结尾2        ,但是这个时候我以6结尾,那么其实3这个位置长度也是3了,

(所以,我们要找出最大的那个长度,再重新赋值到这个数的每个素因子上) 这个时候就能解出来了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iostream>
#include<map>
#define mod 1000007
#define maxn 200001
using namespace std;
typedef long long ll;
ll a[maxn];
ll dp[maxn];
ll n;
int main(){
cin>>n;
for(int i=;i<n;i++){
cin>>a[i];
}
for(int i=;i<n;i++){
ll z=a[i];
map<ll,ll> mp;
vector<int> q;
while(z!=){
ll t=(ll)sqrt((double)z);//必须要加,不然会超时
ll j=;
for(;j<=t;j++){
if(z%j==){
if(mp[j]==) q.push_back(j);
mp[j]++;
z/=j;
break;
}
}
if(j==t+){
if(mp[z]==) q.push_back(z);//判断素数情况
break;
}
}
ll mx=-;
for(int j=;j<q.size();j++){//找出最大长度
dp[q[j]]++;
if(mx==-) mx=dp[q[j]];
else mx=max(mx,dp[q[j]]);
}
for(int j=;j<q.size();j++){//重新赋到每一个位置
dp[q[j]]=mx;
}
}
ll x=dp[];
for(int i=;i<maxn;i++){
x=max(x,dp[i]);
}
cout<<max((ll),x);
}

Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)的更多相关文章

  1. 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...

  2. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  3. Codeforces Round #162 (Div. 2)

    A. Colorful Stones (Simplified Edition) 模拟. B. Roadside Trees (Simplified Edition) 每次转移时,只需要爬到\(min( ...

  4. Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    B. Making Sequences is Fun time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. Codeforces Round #162 (Div. 2) A~D 题解

    A. Colorful Stones (Simplified Edition) time limit per test 2 seconds memory limit per test 256 mega ...

  6. Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)

    题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...

  7. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  8. Codeforces Round #670 (Div. 2) D. Three Sequences 题解(差分+思维+构造)

    题目链接 题目大意 给你一个长为n的数组a,要你构造一个非严格单调上升的数组b和一个非严格单调下降的数组c,使得\(b_i+c_i=a_i\) 要你使这两个数组b,c中最大的元素最小,还有q次修改(q ...

  9. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

随机推荐

  1. MAVEN中的Scope

    Dependency Scope 在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用6个值: *im ...

  2. Codeforces 741 D - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths

    D - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 思路: 树上启发式合并 从根节点出发到每个位置的每个字符的奇偶性记为每个位 ...

  3. 异常:Error resolving template "xxx", template might not exist or might not be accessible...解决办法

    在开发环境下正常,但使用jar运行时,报错Error resolving template template might not exist or might not be accessible,意思 ...

  4. Log4Net 常见格式说明(不断更新中)

    用户名  %username pc版本 另起一行 %newline

  5. 【js】【图片显示】js控制html页面显示图片方式

    js控制html页面显示图片方式,只需要引入“jquery-1.11.2.min.js” js: /* 引用 <script src="jquery-1.11.2.min.js&quo ...

  6. vue-详情列表偷懒遍历

    假如数据格式是这样的: 文案的字段名和数据的字段名完全对应,我们在处理数据的时候,就可以用: 完美:

  7. .gitconfig

    [user] name = 1111 email = 111@111.com[credential] helper = store

  8. 银行卡卡bin

    卡BIN指的是发卡行识别码,英文全称是 Bank Identification Number,缩写为 BIN.中文即“银行识别代码”  银行卡的卡号是标识发卡机构和持卡人信息的号码 一般是13-19位 ...

  9. WPF listbox实现多列显示数据

    一.每行显示固定列数 <ListBox ItemsSource="{Binding DataList}" Style="{DynamicResource ListB ...

  10. spring mvc将对象转换为json返回的配置

    之前在spring 3中用的好好的MappingJacksonHttpMessageConverter转换器,将对象转为json响应给浏览器,在spring4中,报错. Cannot create i ...