/*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<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)