P2690 Pick up apples
F[I][J][K] Indicates
I=1 or 2, which is the J-moment cow under which tree
J means time.
K means to transfer k-times.
If the current 1th tree falls on an apple
F[1][t][left]=max (f[1][t-1][left],f[2][t-1][left-1]) +1;
If the current 2nd tree falls on an apple
F[2][t][left]=max (f[2][t-1][left],f[1][t-1][left-1]) +1;
1#include <iostream>2#include <cstdio>3#include <queue>4#include <algorithm>5#include <cmath>6#include <ctime>7#include <cstring>8 #defineINF 21474836479 #definefor (I,A,B) for (register int i=a;i<=b;i++)Ten #defineP (a) Putchar (a) One #defineG () GetChar () A //by War - //2017.10.18 - using namespacestd; the intN; - intx; - intW; - intf[Ten][1010][ +]; + intans; - void inch(int&x) + { A inty=1; at CharC=g (); x=0; - while(c<'0'|| C>'9') - { - if(c=='-') -y=-1; -C=g (); in } - while(c<='9'&&c>='0') x=x*Ten+c-'0', c=g (); tox*=y; + } - voidOintx) the { * if(x<0) $ {Panax NotoginsengP'-'); -x=-x; the } + if(x>9) O (x/Ten); AP (xTen+'0'); the } + - voidZyintt) $ { $f[1][t][0]++; - for(intleft=2; left<=w;left+=2) -f[1][t][left]=max (f[1][t-1][left],f[2][t-1][left-1])+1; the } - Wuyi voidYzintt) the { - for(intleft=1; left<=w;left+=2) Wuf[2][t][left]=max (f[2][t-1][left],f[1][t-1][left-1])+1; - } About $ intMain () - { - inch(n),inch(w); -for (T,1, N) A { + for(intleft=1; left<=w;left+=2) thef[2][t][left]=f[2][t-1][left]; - for(intleft=0; left<=w;left+=2) $f[1][t][left]=f[1][t-1][left]; the inch(x); the if(x==1) the Zy (t); the Else - YZ (t); in } the for(intI=1; i<=w;i+=2) theAns=max (ans,f[2][n][i]); About for(intI=0; i<=w;i+=2) theAns=max (ans,f[1][n][i]); the O (ans); the return 0; +}
View Code
P2690 Pick up apples