bzoj1750 [Usaco2005 qua]Apple Catching
Description
Input
Output
Sample Input
2
1
1
2
2
1
1
INPUT DETAILS:
Seven apples fall - one from tree 2, then two in a row from tree 1, then
two in a row from tree 2, then two in a row from tree 1. Bessie is
willing to walk from one tree to the other twice.
Sample Output
6
OUTPUT DETAILS:
Bessie can catch six apples by staying under tree 1 until the first two
have dropped, then moving to tree 2 for the next two, then returning back
to tree 1 for the final two.
题意是一个人站在树下接苹果,树只有两棵,每一个时刻只有一棵树有苹果掉下来,但是人只能从一棵树移到另一棵树最多m次,求最多能接多少个苹果
dp太水了,f[i][j][0 / 1]表示第i时刻已经移动了j次,当前在第1 / 2棵树下的方案,然后转移自己yy一下吧。或者直接看代码
#include<cstdio>
inline int max(int a,int b)
{return a>b?a:b;}
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,mx;
int f[1001][1001][2];//ǰ i ¸ö¡¢Òƶ¯ j ²½¡¢µ±Ç°Î»ÖÃÊÇ1/2
int a[1001][2];
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
int x=read();
a[i][x-1]=1;
}
for (int i=1;i<=n;i++)
{
f[i][0][0]=f[i-1][0][0]+a[i][0];
f[i][0][1]=f[i-1][0][1]+a[i][1];
for (int j=1;j<=m;j++)
{
f[i][j][0]=max(f[i-1][j-1][1],f[i-1][j][0])+a[i][0];
f[i][j][1]=max(f[i-1][j-1][0],f[i-1][j][1])+a[i][1];
mx=max(mx,f[i][j][0]);
mx=max(mx,f[i][j][1]);
}
}
printf("%d\n",mx);
}
然后我再想了下,好像我们把相邻的相同的数字缩成一个数,用缩掉的数字的个数表示,然后求长度为m+1的最大子串和
比如样例:
7 2
2|1 1|2 2|1 1缩成1 2 2 2
然后显然答案是2 2 2即6
但是有反例
7 2
1 2 1 2 1 2 2
答案是5,这样做是4
我想不用多解释了吧
所以还是老老实实dp吧
bzoj1750 [Usaco2005 qua]Apple Catching的更多相关文章
- bzoj3384[Usaco2004 Nov]Apple Catching 接苹果*&&bzoj1750[Usaco2005 qua]Apple Catching*
bzoj3384[Usaco2004 Nov]Apple Catching 接苹果 bzoj1750[Usaco2005 qua]Apple Catching 题意: 两棵树,每分钟会从其中一棵树上掉 ...
- BZOJ1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227[Submit ...
- bzoj1751 [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec Memory Limit: 64 MB Submit: 168 Solved: 130 [ ...
- Apple Catching(POJ 2385)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9978 Accepted: 4839 De ...
- Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9831 Accepted: 4779 De ...
- 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 ...
- 1755: [Usaco2005 qua]Bank Interest
1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 187 Solved: 162[Su ...
- 1753: [Usaco2005 qua]Who's in the Middle
1753: [Usaco2005 qua]Who's in the Middle Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 290 Solved: ...
- 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果
3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solv ...
随机推荐
- 写在学习linux内核协议栈之前
一直很喜欢内核,但是新手,非常的痛苦啊.现在看一本linux内核协议栈源码解析一书,将自己学习的经历以及 理解记录下来,以备将来回头查漏补缺,同时校正自己的理解错误,自勉
- euctb
- 能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而是可以按片自由搭配 | 36氪
能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而是可以按片自由搭配 | 36氪 能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而 ...
- debuggap,移动端调试新方式
最近发现了一个移动端调试的新技能,这里简单描述一下基本情况. 移动端调试常遇到的问题 手机访问只能看到页面的展现,除此之外看不到任何其他信息 无法像调试PC页面那么方便的查看js.dom.networ ...
- Linux文件io--one简述
什么是文件IO IO就是input/output,输入/输出.文件IO的意思就是读写文件. 文件操作的主要接口API 什么是操作系统API (1)API是一些函数,这些函数是由linux系统提供支持的 ...
- day57:00:26:34
今天开始用博客记录倒计时,也只是为了看看今天做了什么.这也是我第一用博客园记录考研生活了 倒计时57天,我在想每天花时间在这记录生活会不会浪费复习的时间,其实不会的了,不去看微博,少刷新闻....仔细 ...
- C# - List操作- 去掉重复
ChangeList里面会有重复的数据,这时可以这样去掉重复的item // Remove duplicated info var dup = ChangeList.Where(item => ...
- (转)Iphone数组一些基础操作 NSArray/NSMutableArray
/******************************************************************************************* NSArray ...
- [Regular Expressions] Find Plain Text Patterns
The simplest use of Regular Expressions is to find a plain text pattern. In this lesson we'll look a ...
- CSS基础知识笔记(一)
css 样式由选择符和声明组成,而声明又由属性和值组成: 选择符: 又称选择器,指明网页中要应用样式规则的元素,如本例中是网页中所有的段(p)的文字将变成蓝色,而其他的元素(如ol)不会受到影响. 声 ...