標籤:one for close get isp 表示 logs iostream view
P2690 接蘋果
f[i][j][k]表示
i=1或2,表示j時刻cow在哪棵樹下
j表示時刻
k表示轉移了k次
如果當前第1棵樹落蘋果
f[1][t][left]=max(f[1][t-1][left],f[2][t-1][left-1])+1;
如果當前第2棵樹落蘋果
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 #define inf 2147483647 9 #define For(i,a,b) for(register int i=a;i<=b;i++)10 #define p(a) putchar(a)11 #define g() getchar()12 //by war13 //2017.10.1814 using namespace std;15 int n;16 int x;17 int w;18 int f[10][1010][40];19 int ans;20 void in(int &x)21 {22 int y=1;23 char c=g();x=0;24 while(c<‘0‘||c>‘9‘)25 {26 if(c==‘-‘)27 y=-1;28 c=g();29 }30 while(c<=‘9‘&&c>=‘0‘)x=x*10+c-‘0‘,c=g();31 x*=y;32 }33 void o(int x)34 {35 if(x<0)36 {37 p(‘-‘);38 x=-x;39 }40 if(x>9)o(x/10);41 p(x%10+‘0‘);42 }43 44 void zy(int t)45 {46 f[1][t][0]++; 47 for(int left=2;left<=w;left+=2)48 f[1][t][left]=max(f[1][t-1][left],f[2][t-1][left-1])+1;49 }50 51 void yz(int t)52 {53 for(int left=1;left<=w;left+=2)54 f[2][t][left]=max(f[2][t-1][left],f[1][t-1][left-1])+1;55 }56 57 int main()58 {59 in(n),in(w);60 For(t,1,n)61 {62 for(int left=1;left<=w;left+=2)63 f[2][t][left]=f[2][t-1][left];64 for(int left=0;left<=w;left+=2)65 f[1][t][left]=f[1][t-1][left];66 in(x);67 if(x==1)68 zy(t);69 else70 yz(t);71 }72 for(int i=1;i<=w;i+=2)73 ans=max(ans,f[2][n][i]);74 for(int i=0;i<=w;i+=2)75 ans=max(ans,f[1][n][i]);76 o(ans);77 return 0;78 }
View Code
P2690 接蘋果