Advertising
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/43970671");}
--silver
F[I][J] indicates that the minimum value of J has been skipped to the first I
Then the violence shifted from the past.
Its time complexity is 125 million, but the constant is far less than 1.
--bronze
As in the Silver group, just change the size of the array, then m directly assigns a value of 1.
Silver Group Code:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 505#define INF 0X3F3F3F3F3F3F3F3FLLusing namespace STD;Long LongN,m;Long LongF[n][n],x[n],y[n];intMain () {Freopen ("Test.in","R", stdin);Cin>>n>>m;intI,j,k; for(i=1; i<=n;i++)Cin>>x[i]>>y[i];memset(F,0x3f,sizeoff); f[1][0]=0; for(i=2; i<=n;i++) { for(j=0; j<i-1&&j<=m;j++) { for(k=i-1; i-k-1<=j&&k;k--) {f[i][j]=min (f[i][j],f[k][j-(i-k-1)]+ABS(X[i]-x[k]) +ABS(Y[i]-y[k])); } } }Long LongAns=inf; for(i=0; i<=m;i++) Ans=min (Ans,f[n][m]);cout<<ans<<endl;return 0;}
"BZOJ3892" "Usaco2014 Dec" Marathon (Silver and Bronze) violent motion rules