God's ladder [DP]
来源:互联网 发布:淘宝买烟暗语 编辑:程序博客网 时间:2024/06/05 12:01
Description
天明来到神之宫殿,在他眼前出现了若干个石柱,每个石柱上有1枚金币,天明可以任意选择一个石柱开始,然后向前方的石柱瞬移,而且他所瞬移到的石柱的高度必须要大于现在所在石柱的高度。
求天明所能获得的最大金币数以及任意一种可以获得这么多金币的路线(每个石柱的高度)。
Input
第一行一个数n,表示石柱的个数。
然后2~n+1行,每行一个石柱的高度h[i],分别是1,2,,n石柱的高度。
2
Output
第一行为一个数m,表示最大金币数。
2~m+1行,每行一个数,分别是每次所瞬移到的石柱的高度。
Sample Input
7
3
1
2
5
9
6
7
Sample Output
5
1
2
5
6
7
Hint
题意
题解:
AC代码
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;int a[300100];int dp[300100];int par[300100];int tp[300100];void print(int nxt){ if(!nxt) return ; print(par[nxt]); printf("%d\n",a[nxt]);}int main(){ int n; scanf("%d",&n); for (int i = 1;i <= n; ++i){ scanf("%d",&a[i]); par[i] = -1; } int top = 0; for (int i = 1; i <= n; ++i){ int pos = lower_bound(dp,dp+1+top,a[i])-dp; dp[pos] = a[i]; //更新长度操作 par[i] = tp[pos-1]; //记录前驱 tp[pos] = i; //记录位置 //printf("*%d %d %d %d*\n",par[i],tp[pos],pos,dp[pos]); if (pos>top) top++; } printf("%d\n",top); print(tp[top]); return 0;}
阅读全文
0 0
- God's ladder [DP]
- 1275: God's ladder [DP]
- [HPU]1275: God's ladder [DP]
- [HPU OJ 1275] God's ladder [ LIS 及路径输出]
- God's Note
- POJ3107-God father(树形dp??)
- CF279C Ladder 简单DP
- GOD
- Got God's Root ,still her Guest
- TOJ 4127. God Le's Tree
- UESTC 1273 God Qing's circuital law
- TaoSama Becomes the God of Stocks dp
- God Father (树形dp 树的重心)
- [CodeForces 279C] Ladder (DP)
- Seasons' Show (Oh My God Your Granddaughter's Gone) [UNFINISHED]
- God Chang's interview——异或
- hdu 2809 God of War //状态压缩DP
- HDU - 2809 God of War (DP+状态压缩)
- 大数据统计分析架构-netty部分
- js模拟反转数组reverse()
- JZOJ4726. 【NOIP2016提高A组模拟8.22】种花(2017.8DP&贪心专题)
- JQuery之DOM函数文档操作学习总结
- Git SSH Key 生成步骤
- God's ladder [DP]
- Oracle控制文件详解
- Memcached (简介及安装)--学习笔记(一)
- 习题 5.11 一个球从100m高度自由落下,每次落地后反跳回原高度的一半,再落下,再反弹。求它在第10次落地时,共经过多少米,第10次反弹多高。
- 古文觀止卷八_圬者王承福傳_韓愈
- 已知前序遍历和中序遍历的结果求后序遍历
- js反转字符串方法
- 使用ImageLoader实例 进行加载图片
- 难忘的JS传参问题