P2690 Pick up apples

Source: Internet
Author: User

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

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.