This article ljh2000
Author Blog: http://www.cnblogs.com/ljh2000-jump/
Reprint please specify the source, infringement must investigate, retain the final interpretation right!
Title Link: HDU5730
Positive solution: divide and Cure $fft$
Problem Solving Report:
Divide and cure $+fft$ template problem.
Easy to find a $o (n^2) $ $dp$ equation, is a convolution form, in the division process, with the left to update the right, do a $fft$.
Be careful not to empty the array every time.
#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include < complex> #include <cmath> #include <cstring>using namespace std;typedef long Long ll;typedef complex< double> c;const int maxn = 400011;const int mod = 313;const double pi = ACOs ( -1); int n,r[maxn],l; LL OUT[MAXN],TMP[MAXN],A[MAXN]; c c[maxn],d[maxn];inline void FFT (c *a,int n,int f) {for (Int. i=0;i<n;i++) if (I<r[i]) swap (a[i],a[r[i]]); for (int i=1 ; i<n;i<<=1) {C wn (cos (pi/i), sin (f*pi/i)), x,t;for (int j=0;j<n;j+= (i<<1)) {C W (1,0); for (int k=0;k <I;K++,W*=WN) {x=a[j+k]; t=a[j+k+i]*w;a[j+k]=x+t;a[j+k+i]=x-t;}}} inline void Calc (LL *aa,int len1,ll *bb,int len2) {int ll=len1+len2; int len=1; L=0;for (; len<=ll;len<<=1) l++; r[0]=0;for (int i=0;i<len;i++) r[i]= (r[i>>1]>>1) | ((i&1) << (L-1)); for (int i=0;i<len1;i++) c[i]=0,c[i]=aa[i];for (int i=len1;i<=len;i++) c[i]=0;for (int i=0;i<len2;i++) d[i]=0,d[i]=bb[i];for(int i=len2;i<=len;i++) d[i]=0; FFT (c,len,1); FFT (d,len,1); for (int i=0;i<=len;i++) c[i]*=d[i]; FFT (C,len,-1), for (int i=0;i<=len1+len2;i++) tmp[i]= (LL) (C[i].real ()/len+0.5);} inline void FFT (int l,int r) {int mid= (l+r) >>1; calc (out+l,mid-l+1,a,r-l+1); for (int i=mid-l+1;i<=r-l;i++) out[ L+i]+=tmp[i],out[l+i]%=mod;} inline void CDQ (int l,int r) {if (l==r) return; int mid= (L+R) >>1; CDQ (L,mid); FFT (L,R); CDQ (mid+1,r);} inline void work () {while (1) {scanf ("%d", &n), if (n==0) break;for (int i=1;i<=n;i++) scanf ("%lld", &a[i]), A[i] %=mod;memset (out,0,sizeof (out)); out[0]=1; CDQ (0,n); out[n]+=mod;out[n]%=mod;printf ("%lld\n", Out[n]);}} int main () {work (); return 0;}
HDU5730 Shell Necklace