Apple Catching POJ
来源:互联网 发布:网络校时软件 编辑:程序博客网 时间:2024/06/15 04:19
题意:
输入第一行,t,mv;
后面跟t行;表示,两棵树每秒有一棵树掉苹果,共t秒钟,最多移动mv次,然后输入每秒掉苹果的树(1或2)t行,问不超过最多移动次数,最多能接到多少苹果?
思路:简单的动态规划,dp数组储存i秒移动j次能接到的最大苹果数
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1001;
int dp[maxn][35];
int n[maxn];
int main()
{
int t;
int mv;
while(scanf("%d%d",&t,&mv)!=EOF)
{
for(int i=1;i<=t;i++)//输入数据
{
scanf("%d",&n[i]);
}
memset(dp,0,sizeof(dp));
if(n[1]==1)//初始情况赋值
dp[1][0]=1;
else
dp[1][1]=1;
for(int i=2;i<=t;i++)//动态规划转移方程
for(int j=0;j<=mv;j++)
{
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+(j%2+1==n[i]));
//i秒比i-1秒多移动一次 //若j为偶数(j%2==0(加1表示没移动还在1树下))相当于没移动看当前时间对应当前所在树下是否有果子
dp[i][j]=max(dp[i][j],dp[i-1][j]+(j%2+1==n[i]));
//i秒相对i-1秒没移动 //若j为奇数(j%2==1(加1表示移动了在2树下))相当于了移动看当前时间对应当前所在树下是否有果子
}
cout<<dp[t][mv]<<endl;
}
}
- POJ 2385 Apple Catching
- POJ-2385-Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- Apple Catching.(POJ-2385)
- poj 2385 Apple Catching
- poj 2385 Apple Catching
- POJ 2385Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- POJ 2385 Apple Catching
- poj-2385-Apple Catching
- Apple Catching POJ 2385
- 链表中环的入口节点
- 51Nod 1535 思维+DFS
- 关于mybatis配置文件中的resultMap和resultType
- java每日一练
- 51nod 1019 逆序数 (分治)
- Apple Catching POJ
- Spark核心RDD:combineByKey函数详解
- CentOS7下Hive-2.1.1安装
- mybatis开发dao方法
- Sql 中存储过程详细案例
- centos 查找文件
- enum枚举类型的使用(上)
- 数据库
- (web服务器)到嵌入式Linux系统