hrbeu 哈工程 Who Is In Front of Me
2012-10-09 22:37
357 查看
//DP入门题状态转移方程很容易想到 //关键是构建pre数组,多少有点像KMP里面构建的next数组 #include <stdio.h> #include <string.h> #define MAX 50100 int a[MAX],pre[MAX],dp[MAX]; int n; int main() { int i,j,T,max; scanf("%d",&T); while(T--) { scanf("%d",&n); pre[1]=0; dp[1]=0; scanf("%d",&a[1]); max=0; for(i=2; i<=n; i++) { scanf("%d",&a[i]); if(a[i]<a[i-1]) { pre[i]=i-1; dp[i]=dp[i-1]+1; } else { for(j=pre[i-1]; j!=0 && a[i]>=a[j] ; j=pre[j]) ; pre[i]=j; if(!pre[i]) dp[i]=0; else dp[i]=dp[pre[i]]+1; } max=dp[i]>max?dp[i]:max; } // for(i=1; i<=n; i++) printf("%d ",pre[i]); printf("\n"); // for(i=1; i<=n; i++) printf("%d ",dp[i]); printf("\n"); printf("%d\n",max); } return 0; }
相关文章推荐
- 2013资格赛——Who Is In Front of Me
- who is in front of me 解题报告
- HEU_ Who Is In Front of Me
- Who Is In Front of Me(hrbeu1216)
- ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.
- Who is in me? -- Freeware on Windows
- Effective C++ Item 38 通过复合塑模出 has-a 或 is-implemented-in-terms-of
- xcode 中出现 Implicit declaration of function 'xxxx' is invalid in C99” 警告的解决办法
- 继承“JdbcDaoSupport”后,报“The hierarchy of the type AccoutDaoImpl is inconsistent”的解决方案
- RunningMapReduceExampleTFIDF - hadoop-clusternet - This document describes how to run the TF-IDF MapReduce example against ascii books. - This project is for those who wants to experiment hadoop as a skunkworks in a small cluster (1-10 nodes) - Google Pro
- The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain
- Comparison of user class objects is not supported in Linq to entities
- error: request for member '*' in '*', which is of non-class type '*'
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- The hierarchy of the type is inconsistent
- MyEclipse中无法部署项目到tomcat中的解决方法( deployment is out of date due to changes in the underlying ......)
- 使用RecyclerView CardView相关问题 解决The hierarchy of the type is inconsistent问题
- Xcode解决“Implicit declaration of function 'XXX' is invalid in C99” 警告或报错
- what is the difference of select single and select up to one row in abap
- The hierarchy of the type is inconsistent