思路:

简单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. springboot 多数据源(三种数据库连接池--JDBC,dbcp2,Druid)

    本文使用的是springboot2.0(在配置数据源时和springboot1.X略有区别) 首先:springboot默认支持的连接池有dbcp,dbcp2, tomcat, hikari四种连接池 ...

  2. linux地址映射1、2、3(⭐⭐⭐)

    欢迎关注瘋耔新浪微博:http://weibo.com/cpjphone 一.线性映射与非线性映射                                                   ...

  3. sql server filter table name

    https://stackoverflow.com/questions/26577464/how-to-find-a-table-in-sql-server-if-only-the-partial-t ...

  4. damon

    不管是否有-f参数,最终程序都会进入 fuse_loop_mt 循环中,在helper.c的fuse_main_common函数中. 1. 有-f参数.这种情况下fuse_setup_common函数 ...

  5. My Notes

    1.类似于border.margin.padding的四个方向数值顺序为上右下左.2.属性z-index参数值越大,则被层叠在最上面.3.标签<a>和属性display:block和适合在 ...

  6. BM算法模式匹配——字符串与KMP比较

    下面是代码:BM是什么参考阮一峰老师的讲解  点击打开链接 #include<iostream> #include<algorithm> #include<string. ...

  7. 【SCOI 2009】 Windy数

    [题目链接] 点击打开链接 [算法] 数位DP,注意处理前导零的情况 [代码] #include<bits/stdc++.h> using namespace std; #define M ...

  8. angularjs 获得当前元素属性

    先用 console.log(this)查看下当前被点击元素的 this 属性,然后可以看见里面有个$index属性,该属性指向的就是DOM元素列表中当前被点击的那个DOM的下标,只需要使用this. ...

  9. 分享几篇文章(PDF版)

    后天就要回老家了,除了团团年估计也没有其他好玩的,就琢磨下点经典文章带回去看看. Google一番找到了老赵很早以前的文章: http://www.cnblogs.com/JeffreyZhao/ar ...

  10. 附加类型“UniversalReviewSystem.Models.ApplicationUser”的实体失败,因为相同类型的其他实体已具有相同的主键值。在使用 "Attach" 方法或者将实体的状态设置为 "Unchanged" 或 "Modified" 时如果图形中的任何实体具有冲突键值

    在使用asp.net Identity2 的 UserManager RoleManager 时,同时还有其他仓储类型接口,能实现用户扩展信息的修改,用户注册没有问题.当修改用户信息时,出现了如下异常 ...