POJ
来源:互联网 发布:js防水涂料检验批 编辑:程序博客网 时间:2024/06/05 06:54
传送门:POJ2385
题意:有两颗苹果树,每分钟会从其中某一颗苹果树上掉下一个苹果来,初始在1号树下,可以在树间移动而不花费时间,但是最多移动w次,问最多能接到多少个苹果。
思路:很明显的我们可以根据移动次数奇偶判断在哪颗树下,用dp[i]表示移动i次最多能接到多少苹果,然后对每一个掉下来的苹果进行O(w)的状态转移就好了。
代码:
#include<iostream>#include<algorithm>#define ll long long#define pb push_back#define fi first#define se second#define pi acos(-1)#define inf 0x3f3f3f3f#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define rep(i,x,n) for(int i=x;i<n;i++)#define per(i,n,x) for(int i=n;i>=x;i--)using namespace std;typedef pair<int,int>P;const int MAXN=100010;int gcd(int a,int b){return b?gcd(b,a%b):a;}int dp[33];int main(){int t, w, id;cin >> t >> w;for(int i = 0; i < t; i++){cin >> id;for(int j = w; j >= 0; j--){if(j & 1){if(id == 2)dp[j]++;elsedp[j + 1] = max(dp[j + 1], dp[j] + 1);}else{if(id == 1)dp[j]++;elsedp[j + 1] = max(dp[j + 1], dp[j] + 1);}}}cout << *max_element(dp, dp + w + 1) << endl; return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- MySQL入门之创建、更新、修改、复制、查看表
- 【转载】深入理解定位父级offsetParent及偏移大小
- 使用css3教你做动画
- PE详解之区块表(节表)和区块(节)(PE详解04)
- Python起步之字典案例(词频统计)
- POJ
- git--标签管理
- CentOS下搭建Java Web开发环境
- android AppOps operation mode设置权限浅析
- c语言
- NOIP2013 Day1 T3 货车运输
- C# winform打印RDLC
- ModelAndView详解
- android_视频播放器(VideoView)