poj2385
来源:互联网 发布:centos yum 升级gcc 编辑:程序博客网 时间:2024/06/08 17:08
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=1005;int f[1005][31];int a[maxn][3];int main(){ int n,k,b; scanf("%d%d",&n,&k); memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { scanf("%d",&b); a[i][b]=1; //第i分钟编号为b的苹果树掉下苹果 } memset(f,0,sizeof(f)); f[1][0]=a[1][1]; for(int i=1;i<=n;i++) for(int j=0;j<=k;j++) { f[i][j]=f[i-1][j]+a[i][j%2+1]; //第i分钟不移动,总共移动了j次 if(j>0) f[i][j]=max(f[i][j],f[i-1][j-1]+a[i][j%2+1]); //移动,总共移动了j次 } int ans=0; for(int j=1;j<=k;j++) ans=max(ans,f[n][j]); printf("%d\n",ans); return 0;}//f[i][j]表示前i分钟移动了j次所获的苹果数
0 0
- poj2385
- poj2385
- poj2385
- poj2385
- poj2385
- poj2385 dp
- poj2385 dp
- poj2385(dp)
- POJ2385【DP】
- dp-poj2385
- poj2385-dp经典
- poj2385 - Apple Catching
- poj2385(DP)
- POJ2385 Apple Catching
- poj2385-dp经典
- POJ2385 Apple Catching 【DP】
- POJ2385 简单DP
- [dp]poj2385 AppleCatching
- 安装Ubuntu分区方法
- 闲来无事,写了个简易计算器
- JZOJ 4889 最长公共回文子序列(搜索)
- 手把手编写自己的 PHP MVC 框架实例教程
- 测试小故事5:纠结与坦然
- poj2385
- 选择客栈 NOIP2011 提高组 Day1 T2
- 两道递推
- 如何用消息系统避免分布式事务?
- Spring Cloud构建微服务架构(一)服务注册与发现
- 2016.11.15 C语言常遇概念问题
- 重写返回按键的监听
- oracle:rman恢复----通过增量备份来恢复
- 【noip2009提高组】 Hankson 的趣味题 欧几里得(数论)