给定一个序列 A,求有多少非空序列 B 满足 B 是 A 的子序列 并且 ∀ k ∈ [1,lenb], k∣bk∀ k ∈ [1,lenb], k∣bk,
// f[i][j]= f[i-1][j] + (f[i-1][j-1] ,a[i]%j==0 )
优化: 枚举 a[i] 的因数作为 j
#include <iostream> #include<vector> #include <algorithm> #define IOS std::ios::sync_with_stdio(0) using namespace std; const int N =1e5+3,M=1e6+3, mod=1e9+7; int n,a[N],f[M] ; vector<int> fac; // f[i][j]= f[i-1][j] + (f[i-1][j-1] ,a[i]%j==0 ) void sov(){ int i,j; f[0]=1; for(i=1;i<=n;i++){ fac.clear(); for(j=1;j*j<=a[i];j++){ if(a[i]%j==0){ fac.push_back(j); if(j*j!=a[i]) fac.push_back(a[i]/j); } } sort(fac.begin(),fac.end()); for(j=fac.size()-1;j>=0;j--) f[fac[j]]=f[fac[j]]+f[fac[j]-1],f[fac[j]]%=mod; } int ans=0; for(i=1;i<=n;i++) ans+=f[i],ans%=mod; cout<<ans<<endl; } signed main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sov(); }
标签:1061C,int,CF,sov,序列,fac,include From: https://www.cnblogs.com/towboa/p/17145518.html