"BZOJ3892" "Usaco2014 Dec" Marathon (Silver and Bronze) violent motion rules

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.