POJ 2385 Apple Catching
来源:互联网 发布:淘宝客服下班结束语 编辑:程序博客网 时间:2024/06/07 06:42
原题链接
思路:
动态规划。
思路:i秒转移j次:dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]) + 第i秒是否接到苹果
dp[i-1][j]: i秒没有转移
dp[i-1][j-1]:i秒转移了
AC代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;int T,W,a[1005],dp[1005][35],ans; int main(){ int i,j; scanf("%d %d",&T,&W); for(i = 1; i <= T; i++){ scanf("%d",&a[i]); } if(a[1] == 1){ dp[1][0] = 1; dp[1][1] = 0; } else{ dp[1][0] = 0; dp[1][1] = 1; } for(i = 2; i <= T; i++){ for(j = 0; j <= W; j++){ if(j == 0){ dp[i][j] = dp[i-1][j] +a[i]%2; continue; } dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]); if(a[i] == j%2 + 1) dp[i][j]++; } } for(i = 1; i <= W; i++){ ans = max(ans,dp[T][i]); } printf("%d\n",ans); return 0;}
1 0
- 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
- 世界上主流的五大浏览器及其内核
- highcharts图表:如何配置坐标轴数据过大是否折算进行单位(k,M,G,T,P,E)替换
- poj 2976 && poj 2728 && poj3621 && bzoj 1486 01分数规划
- 蓝桥杯2017模拟赛-还款计算
- STL在使用算法竞赛中的使用方法 (教程+未完成)
- POJ 2385 Apple Catching
- java虚拟机随手笔记(4)内存调优与案例分析
- 动态配置配置文件路径
- MyBatis总结
- Android SDK Manager和AVD Manager使用
- uva 725(暴力)
- DS18B20的具体操作流程
- Hadoop任务查看管理相关
- Power Network poj1459 最大流