标签:style img cstring printf using detail names -- sqrt
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651
参考:https://blog.csdn.net/u013007900/article/details/42365823
https://blog.csdn.net/visit_world/article/details/52734860
好像这样复杂度就是 \( O(n\sqrt{n} \) 的了。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int rdn() { int ret=0;bool fx=1;char ch=getchar(); while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)fx=0;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘)ret=ret*10+ch-‘0‘,ch=getchar(); return fx?ret:-ret; } const int N=1e5+5,mod=1e9+7; int upt(int x){if(x>=mod)x-=mod;if(x<0)x+=mod;return x;} int n,a[N]; void init() { int n=1e5; a[0]=1; for(int i=1;i<=n;i++) for(int j=1;;j++) { int k0=j*(3*j-1)>>1, k1=j*(3*j+1)>>1; int fx=(j&1)?1:-1; if(k0>i&&k1>i)break; if(k0<=i)a[i]=upt(a[i]+fx*a[i-k0]); if(k1<=i)a[i]=upt(a[i]+fx*a[i-k1]); } } int main() { int T=rdn(); init(); while(T--) n=rdn(),printf("%d\n",a[n]); return 0; }
标签:style img cstring printf using detail names -- sqrt
原文地址:https://www.cnblogs.com/Narh/p/10409257.html