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. 21个项目玩转深度学习:基于TensorFlow的实践详解06—人脸检测和识别——项目集锦

    摘自:https://github.com/azuredsky/mtcnn-2 mtcnn - Multi-task CNN library language dependencies comment ...

  2. linux 内核协助的探测

    Linux 内核提供了一个低级设施来探测中断号. 它只为非共享中断, 但是大部分能够在共 享中断状态工作的硬件提供了更好的方法来尽量发现配置的中断号.这个设施包括 2 个函 数, 在<linux ...

  3. 【43.49%】【hdu3308】LCIS

    Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  4. vue-learning:4-template-v-if-and-v-show

    控制元素可见性的指令 v-if 和 v-show v-if v-else v-else-if :多重判断 template :分组渲染包裹元素 key:管理可复用元素 v-show v-if与v-sh ...

  5. CF1214

    CF1214 C题WA3发的菜鸡还能涨分 A 发现货币面值都是倍数关系,直接暴力枚举第第一种换了多少个更新答案就好了 B 按照题意模拟 C 首先,左括号的数量不等于有括号的数量一定无解 想等的话在括号 ...

  6. LuoguP3045牛券Cow Coupons

    LuoguP3045 [USACO12FEB]牛券Cow Coupons 果然我贪心能力还是太差了 ZR讲过的原题我回来对做法没有一丁点印象 有时候有这样一种题目 每个数有两种不同的价值 你可以选择价 ...

  7. 十二、格式化I/O

    1.fprintf 表头文件 #include<stdio.h> 定义函数 int fprintf(FILE * stream, const char * format,.......); ...

  8. 阿里巴巴java开发手册学习记录,php版

    一.编程规约 (一)命名风格 1.目录使用小写+下划线 home,view,model,admin_view 2.类 UpperCamelCase PhpMailer方法 lowerCamelCase ...

  9. Python_自定义关键字的使用

    1.在Python中新建一个套件MOSAPP(一般为APP名称):New Suite→Directory 2.在套件下新建个资源文件My:New Resource:My 3.在My资源文件库下新建个关 ...

  10. C# 对象与引用变量

    从宏观的角度来看,对象是类的实例.比如: //定义一个名为Someone的类,代表这么一些人(通过指定年龄,性别,性格等基本信息)class Someone {  public int age;  p ...