C. Multiplicity
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an integer array a1,a2,…,an

.

The array b

is called to be a subsequence of a if it is possible to remove some elements from a to get b

.

Array b1,b2,…,bk

is called to be good if it is not empty and for every i (1≤i≤k) bi is divisible by i

.

Find the number of good subsequences in a

modulo 109+7

.

Two subsequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, the array a

has exactly 2n−1

different subsequences (excluding an empty subsequence).

Input

The first line contains an integer n

(1≤n≤100000) — the length of the array a

.

The next line contains integers a1,a2,…,an

(1≤ai≤106

).

Output

Print exactly one integer — the number of good subsequences taken modulo 109+7

.

Examples
Input

Copy
2
1 2
Output

Copy
3
Input

Copy
5
2 2 1 22 14
Output

Copy
13
Note

In the first example, all three non-empty possible subsequences are good: {1}

, {1,2}, {2}

In the second example, the possible good subsequences are: {2}

, {2,2}, {2,22}, {2,14}, {2}, {2,22}, {2,14}, {1}, {1,22}, {1,14}, {22}, {22,14}, {14}

.

Note, that some subsequences are listed more than once, since they occur in the original array multiple times.

题意 : 给你 n 个数字,对于任意位置的数你都可以选择或者不选择,构成一个新的序列,当构成新的序列满足第一个数是1的倍数,第二个数是2的倍数..以此类推询问你方案数有多少

思路分析 :

  比赛的时候写了一个 dp,顺势推过去的,用 01 数组去优化的一个,dp[i][j] 表示到达第 i 个位置,且当前构成的序列可以整除 j 的方案数,但由于 n 很大,想的是用 01 滚动数组优化个,

结果凉掉了,就是有些状态是不会被转移过去,从而造成了丢失

  其实一维 dp 就够, dp[i] 表示当前数作为整除 i 的数的个数,倒着推就可以了

代码示例 :

#define ll long long
const ll maxn = 1e6+5;
const ll maxm = 1e5+5;
const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const ll inf = 0x3f3f3f3f; ll n;
ll a[maxm];
vector<ll>ve[maxn]; void init(){
for(ll i = 1; i <= 1e6; i++){
for(ll j = i; j <= 1e6; j += i){
ve[j].push_back(i);
}
}
}
ll dp[maxn];
void solve(){
//ll pt = 1;
//dp[0][0] = 1, dp[1][0] = 1;
dp[0] = 1;
ll ans = 0;
for(ll i = 1; i <= n; i++){
for(ll j = ve[a[i]].size()-1; j >= 0; j--){
ll x = ve[a[i]][j];
dp[x] = dp[x]+dp[x-1];
dp[x] %= mod;
}
}
for(ll i = 1; i <= n; i++) {
ans += dp[i];
ans %= mod;
// printf("++++ i = %lld %lld\n", i, dp[pt][i]);
}
cout << ans << endl;
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//init();
cin >> n ;
for(ll i = 1; i <= n; i++) scanf("%lld", &a[i]);
init();
solve();
return 0;
}

dp - 递推的更多相关文章

  1. hdu2089(数位DP 递推形式)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. hdu 2604 Queuing(dp递推)

    昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...

  3. Power oj2498/DP/递推

    power oj 2498 /递推 2498: 新年礼物 Time Limit: 1000 MS Memory Limit: 65536 KBTotal Submit: 12 Accepted: 3  ...

  4. BZOJ4321queue2——DP/递推

    题目描述 n 个沙茶,被编号 1~n.排完队之后,每个沙茶希望,自己的相邻的两 人只要无一个人的编号和自己的编号相差为 1(+1 或-1)就行:  现在想知道,存在多少方案满足沙茶们如此不苛刻的条件. ...

  5. Shell Necklace (dp递推改cdq分治 + fft)

    首先读出题意,然后发现这是一道DP,我们可以获得递推式为 然后就知道,不行啊,时间复杂度为O(n2),然后又可以根据递推式看出这里面可以拆解成多项式乘法,但是即使用了fft,我们还需要做n次多项式乘法 ...

  6. hdu 1723 DP/递推

    题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...

  7. UVA 10559 Blocks(区间DP&&递推)

    题目大意:给你玩一个一维版的消灭星星,得分是当前消去的区间的长度的平方,求最大得分. 现在分析一下题目 因为得分是长度的平方,不能直接累加,所以在计算得分时需要考虑前一个状态所消去的长度,仅用dp[l ...

  8. [NOI2009]管道取珠 DP + 递推

    ---题面--- 思路: 主要难点在思路的转化, 不能看见要求$\sum{a[i]^2}$就想着求a[i], 我们可以对其进行某种意义上的拆分,即a[i]实际上可以代表什么? 假设我们现在有两种取出某 ...

  9. HDU 2154 跳舞毯 | DP | 递推 | 规律

    Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...

  10. HDU 5366 dp 递推

    The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...

随机推荐

  1. CentOS服务器安装mysql

    1.配置YUM源 下载mysql源安装包 [root@localhost~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-8 ...

  2. <mvc:annotation-driven /><context:annotation-config/><context:component-scan/>

    <context:annotation-config/> 隐式地向 Spring容器注册AutowiredAnnotationBeanPostProcessor. RequiredAnno ...

  3. 002.MFC_对话框_静态文本_编辑框

    一.建立 名为dialogAndCtl的MFC工程,并添加如图控件 1.将上方static text 控件 Caption属性设置为在文本框中如数文本,可以统计字符 2.edit control控件属 ...

  4. VS2017+QT5.11.2+SeetaFace1.0/SeetaFace2.0的简单实现

    SeetaFace开源引擎GitHub地址:https://github.com/seetaface/SeetaFaceEngine SeetaFace2开源引擎GitHub地址:https://gi ...

  5. scrapy分布式Spider源码分析及实现过程

    分布式框架scrapy_redis实现了一套完整的组件,其中也实现了spider,RedisSpider是在继承原scrapy的Spider的基础上略有改动,初始URL不在从start_urls列表中 ...

  6. 多线程之美7一ReentrantReadWriteLock源码分析

    目录 前言 在多线程环境下,为了保证线程安全, 我们通常会对共享资源加锁操作,我们常用Synchronized关键字或者ReentrantLock 来实现,这两者加锁方式都是排他锁,即同一时刻最多允许 ...

  7. mysql主从之基于gtid的主从复制

    一 GITD介绍 1.1 gtid的含义 Global Transaction Identifier,全局事务标识 阿里云的rds目前已经使用gtid 基于gtid的主从复制原理 每个mysql数据库 ...

  8. ubuntu conda install ERROR missing write permission错误

    报错: ondaIOError: Missing write permissions in: /usr/local/anaconda3 # # You don't appear to have the ...

  9. 关于有向图走“无限次”后求概率/期望的口胡/【题解】HNCPC2019H 有向图

    关于有向图走"无限次"后求概率/期望的口胡/[题解]HNCPC2019H 有向图 全是口胡 假了不管 讨论的都是图\(G=(V,E),|V|=n,|E|=m\)上的情况 " ...

  10. 运维必会之MySQL篇

    第一章 SQL语句 语言分类 1)DDL(data definition language)数据定义语言(create.alter.drop)管理基础数据例如:库.表    #<==运维要熟练, ...