zoukankan      html  css  js  c++  java
  • poj2385 Apple Catching

    思路:

    简单dp。

    实现:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 int t,w,x[1005];
     6 int dp[1005][2][35];
     7 int dfs(int now,int cur,int rem)
     8 {
     9     if(dp[now][cur][rem] != -1)
    10         return dp[now][cur][rem];
    11     if(now == t)
    12         return 0;
    13     int p = dfs(now + 1,cur,rem) + (cur == x[now] - 1);
    14     if(rem >= 1)
    15         p = max(p, dfs(now,1 - cur,rem - 1) + (cur == x[now] - 1));
    16     return dp[now][cur][rem] = p;
    17 }
    18 int main()
    19 {
    20     memset(dp,-1,sizeof(dp));
    21     cin >> t >> w;
    22     for(int i = 0;i < t;i ++)
    23     {
    24         scanf("%d",&x[i]);
    25     }
    26     cout << dfs(0,0,w) << endl;
    27     return 0;
    28 }
  • 相关阅读:
    软硬链接
    查看文件内容
    cp+mv
    cd+rm+pwd
    ls+tree
    绝对路径和相对路径
    Linux目录结构
    修改hostname
    java. util. concurrent. atomic
    git
  • 原文地址:https://www.cnblogs.com/wangyiming/p/6576315.html
Copyright © 2011-2022 走看看