POJ 2385 Apple Catching(01背包)
01背包的基础上增加一个维度表示当前在的树的哪一边。
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std; const int maxn = 1e3+;
int val[][maxn];
int dp[][]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T,W;
cin>>T>>W;
for(int i = ; i < T; i++) {
int x; scanf("%d",&x);
val[x-][i] = ;
}
for(int t = T-; t >= ; t--){
for(int w = W; w >= ; w--){
for(int i = ; i < ; i++){
dp[w][i] += val[i][t];
if(w) dp[w][i] = max(dp[w][i],dp[w-][i^]+val[i^][t]);
}
}
}
printf("%d\n",max(dp[W][],dp[W][]));
return ;
}
POJ 2385 Apple Catching(01背包)的更多相关文章
- poj 2385 Apple Catching 基础dp
Apple Catching Description It is a little known fact that cows love apples. Farmer John has two ap ...
- POJ 2385 Apple Catching
比起之前一直在刷的背包题,这道题可以算是最纯粹的dp了,写下简单题解. 题意是说cows在1树和2树下来回移动取苹果,有移动次数限制,问最后能拿到的最多苹果数,含有最优子结构性质,大致的状态转移也不难 ...
- poj 2385 Apple Catching(dp)
Description It and ) in his field, each full of apples. Bessie cannot reach the apples when they are ...
- poj 2385 Apple Catching(记录结果再利用的动态规划)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有两颗苹果树,在每一时刻只有其中一棵苹果树会掉苹果,而Bessie可以在很短的时 ...
- POJ 2385 Apple Catching【DP】
题意:2棵苹果树在T分钟内每分钟随机由某一棵苹果树掉下一个苹果,奶牛站在树#1下等着吃苹果,它最多愿意移动W次,问它最多能吃到几个苹果.思路:不妨按时间来思考,一给定时刻i,转移次数已知为j, 则它只 ...
- POJ 2385 Apple Catching ( 经典DP )
题意 : 有两颗苹果树,在 1~T 的时间内会有两颗中的其中一颗落下一颗苹果,一头奶牛想要获取最多的苹果,但是它能够在树间转移的次数为 W 且奶牛一开始是在第一颗树下,请编程算出最多的奶牛获得的苹果数 ...
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- POJ 3211 Washing Clothes(01背包)
POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dear ...
- 【POJ】2385 Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13447 Accepted: 6549 D ...
随机推荐
- docker下载安装教程(Linux系统)
原文链接:http://www.studyshare.cn/blog-front//software/details/1160/0一.检查 1.检查安装的docker 命令:yum list inst ...
- MySQL常用配置和性能压力测试:MySQL系列之十五
一.MySQL常用配置 以下所有配置参数以32G内存的服务器为基 1.打开独立的表空间 innodb_file_per_table = 1 2.MySQL服务所允许的同时会话数的上限,默认为151,经 ...
- P2308 添加括号(区间DP)
题目背景 给定一个正整数序列a(1),a(2),...,a(n),(1<=n<=20) 不改变序列中每个元素在序列中的位置,把它们相加,并用括号记每次加法所得的和,称为中间和. 例如: 给 ...
- UVALive - 6442
题目链接:https://vjudge.net/contest/241341#problem/I 题目大意:输入t,t组样例,输入n,m,有n个圆槽,m个硬币,接下来m行代表每个硬币所在的位子,要求你 ...
- 小小粉丝度度熊 二分答案 + two pointer
http://acm.hdu.edu.cn/showproblem.php?pid=6119 发现自己的two pointer能力超弱. 这题是合并时间后,二分答案. 可以知道对于每个时间区间,合法的 ...
- python3+Appium自动化03-Appium元素检测
需要导入方法NoSuchElementException from appium import webdriver from selenium.common.exceptions import NoS ...
- Python解析CSV中的多维字典
CSV文件结构如下,其中字段A为唯一 代码如下,Python27 with open(file_obj+'TEST.CSV','r') as f: #转为字典 Reader=csv.DictReade ...
- 示例1-苏宁每日自动登录打卡-结合Au3
public class SuningAutoClock { public static void AutoClock() throws IOException, InterruptedExcepti ...
- Maven的学习资料收集--(九) 构建SSH项目以及专栏maven
在这里整合一下,使用Maven构建一个SSH项目 1.新建一个Web项目 可以参照前面的博客 2.添加依赖,修改pom.xml <project xmlns="http://maven ...
- SharePoint 2010开发方面的课堂中整理有关问题
SharePoint 2010开发方面的课堂中整理有关问题 这是我这几天在做一个SharePoint开发的课程的时候,大家提出的一些问题,及我的解答,分享给更多的朋友参考一下 这个文档,也可以在这里下 ...