思路:

简单dp。

实现:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int t,w,x[];
int dp[][][];
int dfs(int now,int cur,int rem)
{
if(dp[now][cur][rem] != -)
return dp[now][cur][rem];
if(now == t)
return ;
int p = dfs(now + ,cur,rem) + (cur == x[now] - );
if(rem >= )
p = max(p, dfs(now, - cur,rem - ) + (cur == x[now] - ));
return dp[now][cur][rem] = p;
}
int main()
{
memset(dp,-,sizeof(dp));
cin >> t >> w;
for(int i = ;i < t;i ++)
{
scanf("%d",&x[i]);
}
cout << dfs(,,w) << endl;
return ;
}

poj2385 Apple Catching的更多相关文章

  1. POJ2385——Apple Catching

                                                $Apple~Catching$ Time Limit: 1000MS   Memory Limit: 6553 ...

  2. poj2385 Apple Catching (线性dp)

    题目传送门 Apple Catching Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 154 ...

  3. poj2385 Apple Catching(dp状态转移方程推导)

    https://vjudge.net/problem/POJ-2385 猛刷简单dp的第一天的第一题. 状态:dp[i][j]表示第i秒移动j次所得的最大苹果数.关键要想到移动j次,根据j的奇偶判断人 ...

  4. poj2385 - Apple Catching【动态规划】

    Description It is a little known fact that cows love apples. Farmer John has two apple trees (which ...

  5. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  6. Apple Catching(POJ 2385)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4839 De ...

  7. Apple Catching(dp)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9831   Accepted: 4779 De ...

  8. BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )

    dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1 ...

  9. 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果

    3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18  Solv ...

随机推荐

  1. gson如何转化json数组

    String.JsonObject.JavaBean 互相转换 User user = new Gson().fromJson(jsonObject, User.class); User user = ...

  2. 用secureCRT ssh登陆不显示用户名和路径解决方案 分类: 软件工具学习 2015-03-18 16:52 36人阅读 评论(0) 收藏

    方法1         每次开始的时候输入 bash 虽然只能保存一次,但是简便. 方法2 用       vi ~/.bash_profile   编辑这个文件,  有时会提示这个文件不存在,直 ...

  3. adb 连接时候不弹出授权对话框【转】

    本文转载自:http://blog.csdn.net/sinc00/article/details/44957943 在首次使用adb connect,然后adb shell的时候,常常需要点击弹出的 ...

  4. C#参数数组的用法1

    C# 参数数组 有时,当声明一个方法时,您不能确定要传递给函数作为参数的参数数目.C# 参数数组解决了这个问题,参数数组通常用于传递未知数量的参数给函数. params 关键字 在使用数组作为形参时, ...

  5. 分段控制器--UISegmentedControl 基本用法

    http://blog.csdn.net/heng615975867/article/details/43527295 http://blog.csdn.net/gf771115/article/de ...

  6. 【USACO 2857】 Steady Cow Assignment

    [题目链接] 点击打开链接 [算法] 二分答案,check的时候跑最大流,即可 [代码] #include<bits/stdc++.h> using namespace std; #def ...

  7. 51nod 1095【映射】

    思路: 利用一个map记录初始的,利用一个map记录排序后的. #include <bits/stdc++.h> using namespace std; map<string,in ...

  8. lightoj 1025【区间DP】

    题意: 给出一个word,求有多少种方法你从这个word清除一些字符而达到一个回文串. 思路: 区间问题,还是区间DP: 我判断小的区间有多少,然后往外扩大一点. dp[i,j]就代表从i到j的方案数 ...

  9. Unity3D将来时:IL2CPP(上)

    http://inpla.net/thread-8197-1-1.html Unity3D将来时:IL2CPP(上) (注:本文详细的讲述了C#,Mono,.Net, IL等Unity使用到的概念,如 ...

  10. pyrcharm 编程规范

    正常变量赋值, 等号左右各一个空格: 参数赋值, 等号左右都没有空格: 注释#后面一个空格 类定义和函数定义,前后各两行,而在类的里面定义成员函数,只需要空一行 文件最后一个空行 变量.函数.类最好都 ...