"Algorithm" state compression type DP
Exercises
q=tx+ (t-1) y
For Q≥t (t-1), x, y must have a solution.
So when the distance between the two stones is long>t (t-1), long=t (t-1), the array can be reconstructed.
Note
1. Enter the gravel position unordered, to sort.
2. When s=t is a special sentence.
3. The final solution is to find the minimum value in the n~n+t (but the data is too water =v=).
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn=30000, maxm= the;intA[maxm],b[maxn],f[maxn],l,s,t,n;intMain () {scanf ("%d%d%d%d",&l,&s,&t,&N); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); intans=0; if(s==t) { for(intI=1; i<=n;i++)if(a[i]%s==0) ans++; printf ("%d", ans); return 0; } sort (A,a+n+1); intago=0, mark=0, p=t* (t1)+1; for(intI=1; i<=n;i++) { if(a[i]-ago>=p) b[(Mark+=P)]=1; Elseb[(Mark=mark+a[i]-ago)]=1; Ago=A[i]; } if(l-ago>p) Mark+=p; Elsemark=mark+l-ago; Memset (F,0x3f,sizeof(f)); f[0]=0; for(inti=s;i<=mark;i++) for(intj=s;j<=t;j++) {F[i]=min (f[i],f[i-j]+B[i]); }/*for (int i=0;i<=mark;i++) printf ("%d", i);p rintf ("\ n"); for (int i=0;i<=mark;i++) printf ("%d", B[i]);p rintf ("\ n"); for (int i=0;i<=mark;i++) if (f[i]>1000) printf ("x"), Else printf ("%d", F[i]);*/printf ("%d", F[mark]); return 0;}
View Code
"NOIP" raise group 2005 across the river