POJ 3298 递推,DP
来源:互联网 发布:明星的淘宝店铺 编辑:程序博客网 时间:2024/04/25 06:29
Description
I have a sequence Fred of length n comprised of integers between 1 and n inclusive. The elements of Fred are pairwise distinct. I want to find a subsequence Mary of Fred that is as long as possible and has the property that:
Mary0 > Mary1 < Mary2 > Mary3 < ...
Input
The first line of input will contain a single integer T expressed in decimal with no leading zeroes. T will be at most 50. T test cases will follow.
Each test case is contained on a single line. A line describing a test case is formatted as follows:
n Fred0 Fred1 Fred2 ... Fredn-1.
where n and each element of Fred is an integer expressed in decimal with no leading zeroes. No line will have leading or trailing whitespace, and two adjacent integers on the same line will be separated by a single space. n will be at most 30000.
Output
Sample Input
45 1 2 3 4 55 5 4 3 2 15 5 1 4 2 35 2 4 1 3 5
Sample Output
1253
Source
Source Code
Problem: 3298 User: bingshenMemory: 252K Time: 172MSLanguage: C++ Result: Accepted- Source Code
#include<stdio.h>#include<string.h>int a[30005];int main(){int i,t,n,m,ans;bool s;scanf("%d",&t);while(t--){ans=1;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);m=a[1];s=true;for(i=2;i<=n;i++){if(m<a[i]&&s)m=a[i];else if(m>a[i]&&!s)m=a[i];else if(m>a[i]&&s){m=a[i];s=false;ans++;}else if(m<a[i]&&!s){m=a[i];s=true;ans++;}}printf("%d/n",ans);}return 0;}
- POJ 3298 递推,DP
- poj Chocolate dp递推+精度问题
- poj 2506 Tiling dp 递推
- 【poj 3176】 Cow Bowling 递推dp
- POJ 2229 Sumsets(dp 递推)
- poj 3597 Polygon Division(dp递推)
- poj 1157 简单递推dp
- POJ 1850 递推 也是 dp 的一种啊
- [poj 3254] Corn Fields 状态压缩DP(递推)
- POJ 3420 Quad Tiling DP?递推?+矩阵快速幂
- 【POJ 2663】Tri Tiling(dp|递推)
- POJ 1163 The Triangle【DP】递归和递推
- hdu1438 dp递推
- poj3786(DP,递推)
- hdu4489 dp+递推
- hdu5375 dp+递推
- hdu5286 dp+递推
- 期望dp递推
- PowerShell2.0之桌面计算机维护(八)关闭或重启远程计算机
- 众所周知的局域网聊天软件
- 客户细分和客户分群
- C核心技术手册(二十五)
- instanceof, isinstance,isAssignableFrom的区别
- POJ 3298 递推,DP
- 无题
- JavaScript查找页面文字
- 张瑞敏的读书笔记:凡墙皆是门
- Win7与Win2003之间的兼容性问题
- JavaScript滚动到树的选择结点
- Could not create resource factory 解决方案
- 2010后,MSSQL增加了新特性。
- socket编程原理