P2690 接蘋果

來源:互聯網
上載者:User

標籤: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 接蘋果

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.