POJ 1964 Cow Cycling (DP)

Source: Internet
Author: User

/*The first thought of the two-dimensional maintenance of the first few cows and the number of laps later found that each cow's energy is following each state, so add one-dimensional f[i][j][k] said that the first bull-lead J has consumed the K physical transfer words divided into two categories 1. Change a cow, then move from F[i][j][k to f[. I+1][J][J] 2. Do not change the enumeration I lead a few laps L f[i][j-l][k-l*l] transfer to f[i][j][k] Time + +*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 110using namespacestd;intn,d,e,f[maxn][maxn][maxn],ans=0x7fffffff;intMain () {scanf ("%d%d%d",&n,&e,&d); Memset (F,127/3,sizeof(f)); f[1][0][0]=0;  for(intI=1; i<=n;i++)       for(intj=1; j<=d;j++)         for(intk=1; k<=e;k++)          {               for(intL=1; l<=d;l++)//It's just a few laps ahead.              {                if(j<l| | K&LT;L*L)Continue; F[I][J][K]=min (f[i][j][k],f[i][j-l][k-l*l]+1); } f[i+1][j][j]=min (f[i+1][j][j],f[i][j][k]);//change a cow to lead          }     for(intI=1; i<=e;i++) ans=min (ans,f[n][d][i]); printf ("%d\n", ans); return 0;}

POJ 1964 Cow Cycling (DP)

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.