不是原创的,自己写的递推方程有问题。。。。只过了10%
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n, a[1005], dp[1005];//a数组是单调递增的
set<int> st;
vector<int> f[100005];//f[j]是j的因数集合
int calc(int p, int q) {//从a[x]到a[y]的可能的方案数(中间可能有障碍)
int x = a[q] - a[p];
int ans = 0;
st.insert(x);
for (int i = 0; i < f[x].size(); i++) {
if (st.find(f[x][i]) != st.end()) {
continue;
} else {
ans++;
st.insert(f[x][i]);
}
}
return ans;//当前插入了ans个
}
signed main() {
ios::sync_with_stdio(false);
// freopen("ccf-csp_202104-4_cin.txt", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= a[n] / 2; i++) {
for (int j = 2 * i; j <= a[n]; j += i) {
f[j].push_back(i);//j的因数
}
}
dp[1] = 1;
for (int i = 1; i <= n; i++) {
st.clear();
for (int j = i - 1; j >= 1; j--) {
int t = calc(j, i) % mod;
dp[i] = (dp[i] + dp[j] * t) % mod;
cout << "dp[" << i << "]:" << dp[i] << "||" << "dp[" << j << "]" << dp[j] << "*" << t << endl;
}
cout << endl << endl;
}
cout << dp[n] % mod;
return 0;
}