topcoder srm 684 div.2

本文从WordPress迁移而来, 查看全部WordPress迁移文章

题目链接:DivFreed2

题意 & 题解:

一个数组,任意两个相邻的数字A, B(A在前,B在后),要满足条件 A<=B 或 A%B!=0,求有多少种可能的数组,答案mod 1^9+7 1<=n<=10,数组长度,1<=k<=10^5,数组每个元素的大小. 滚动数组,dp过程中,复杂度和筛素数一样,写法也类型

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

#define scf scanf
#define ptf printf
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int INF = 0x3f3f3f3f;
const int MAXN = 11;
const int MAXK = 100010;
const int MOD = 1000000007;

LL dp[2][MAXK], sum;

class DivFreed2 {
public:
int now, pre;
int count(int n, int k) {
pre = 0;
now = 1;
sum = 0LL;

for (int i = 1; i <= k; i++) {
dp[pre][i] = 1LL;
sum++;
}
for (int id = 2; id <= n; id++) {
LL s = 0LL;
for (int i = 1; i <= k; i++) {
dp[now][i] = sum;
for (int j = i + i; j <= k; j += i) {
dp[now][i] = (dp[now][i] - dp[pre][j] + MOD) % MOD;
}
s = (s + dp[now][i]) % MOD;
}
swap(now, pre);
sum = s;
}

return sum;
}
};