【POJ2385】Apple Catching(简单DP)
来源:互联网 发布:微信公众号源码下载 编辑:程序博客网 时间:2024/04/20 13:36
记录一个菜逼的成长。。
题目大意:两棵树,有T秒钟,每秒钟都会下落一个苹果,接下来T行表示下落苹果的树的编号。最多有W次交换次数,初始在1树。
dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]);
还要判断现在所在的树是否有苹果落下。
还要加上(j%2) + 1 == tree[i]; 0次是在1树, 所以如果交换次数是奇数则在第二棵树,判断i秒钟苹果是否在第二棵树落下
PS:DP的题还是要记一下。。话说刚开始没看懂什么意思。。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cstdlib>#include <vector>#include <set>#include <map>#include <queue>#include <stack>#include <list>#include <deque>#include <cctype>#include <bitset>#include <cmath>using namespace std;#define ALL(v) (v).begin(),(v).end()#define cl(a) memset(a,0,sizeof(a))#define bp __builtin_popcount#define pb push_back#define fin freopen("D://in.txt","r",stdin)#define fout freopen("D://out.txt","w",stdout)#define lson t<<1,l,mid#define rson t<<1|1,mid+1,r#define seglen (node[t].r-node[t].l+1)#define pi 3.1415926#define e 2.718281828459typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> PII;typedef pair<LL,LL> PLL;typedef vector<PII> VPII;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;template <typename T>inline void read(T &x){ T ans=0; char last=' ',ch=getchar(); while(ch<'0' || ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; x = ans;}inline bool DBread(double &num){ char in;double Dec=0.1; bool IsN=false,IsD=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&in!='.'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){IsN=true;num=0;} else if(in=='.'){IsD=true;num=0;} else num=in-'0'; if(!IsD){ while(in=getchar(),in>='0'&&in<='9'){ num*=10;num+=in-'0';} } if(in!='.'){ if(IsN) num=-num; return true; }else{ while(in=getchar(),in>='0'&&in<='9'){ num+=Dec*(in-'0');Dec*=0.1; } } if(IsN) num=-num; return true;}template <typename T>inline void write(T a) { if(a < 0) { putchar('-'); a = -a; } if(a >= 10) write(a / 10); putchar(a % 10 + '0');}/******************head***********************/const int maxn = 1000 + 10;int dp[maxn][35],tree[maxn];int main(){ int T,W; while(~scanf("%d%d",&T,&W)){ cl(dp); for( int i = 1; i <= T; i++ ){ scanf("%d",tree+i); } for( int i = 1; i <= T; i++ ){ dp[i][0] = dp[i-1][0] + (tree[i] == 1);//交换0次是在1树,判断此时是否有苹果落下。 for( int j = 1; j <= W; j++ ){ dp[i][j] = max(dp[i-1][j] , dp[i-1][j-1]) + ((j % 2) + 1 == tree[i]); } } int ans = 0; //不一定是交换次数最大 ,收到的苹果最多。 for( int i = 1; i <= W; i++ ){ ans = max(dp[T][i],ans); } printf("%d\n",ans); } return 0;}
0 0
- 【POJ2385】Apple Catching(简单DP)
- POJ2385-Apple Catching-简单dp
- POJ2385 Apple Catching 【DP】
- POJ2385 Apple catching(dp)
- POJ2385 Apple Catching (dp)
- POJ2385 Apple Catching(DP/递推)
- poj2385 - Apple Catching
- POJ2385 Apple Catching
- poj2385 Apple Catching
- POJ2385--Apple Catching
- POJ2385-Apple Catching
- poj2385 Apple Catching
- POJ2385-Apple Catching
- POJ2385 Apple Catching
- poj2385 Apple Catching
- Apple Catching 简单DP
- POJ2385 Apple Catching 动态规划
- 【动态规划】poj2385 Apple Catching
- SEO与标签的语义化
- 如何成为一名黑客(网络安全从业者)——网络攻击技术篇(3/8 网络协议欺骗)
- some math problems solved by Recursion & divide and conquer
- 【一步步学OpenGL 8】 -《缩放变换》
- 【Java TCP/IP Socket】TCP Socket通信中由read返回值造成的的死锁问题(含代码)
- 【POJ2385】Apple Catching(简单DP)
- 平台总线(二)
- Android面试基础
- 如何理解递归
- android中activuty的简单总结
- Linux - C预习内容(七)
- java中常用的加密方式
- 学习python写网络爬虫(一)
- 从零开始学习Nodejs(一)