HDOJ-5087-Revenge of LIS II
来源:互联网 发布:分割图片的软件 编辑:程序博客网 时间:2024/05/16 18:28
http://acm.hdu.edu.cn/showproblem.php?pid=5087
这是昨天Bestcoder比赛的题目,开始ACCEPT了,好开心,结果后来又被hack掉了,呜呜。
简要说一下我的问题,这个代码犯了好几次错误,唉。
犯的错误在代码中注释了出来。发现我编写代码都不过脑子。MD,算法对否?代码是要表达这个算法吗?
这两个问题以后在编写时要常思考
#include<stdio.h>#include<string.h>int T,N;int dp[1005];int a[1005];int count[1005];int main(){int i,j,max;int c;scanf("%d",&T);while(T--){scanf("%d",&N);memset(count,0,sizeof(count));memset(dp,0,sizeof(dp));for(i=1;i<=N;i++){scanf("%d",&a[i]);}dp[1]=1;count[1]=1;for(i=2;i<=N;i++){//开始把count[i]初始化为1,出错dp[i]=max=1;//寻找LISfor(j=i-1;j>=1;j--){if(a[i]>a[j]){//开始居然写a[j]+1>max,,,if(dp[j]+1>max){max=dp[j]+1;}}}dp[i]=max;//寻找LIS路径数,即//以a[i]结尾最长递增子序列个数for(j=i-1;j>=1;j--){if(a[j]<a[i] && dp[j]==max-1)
<span style="white-space:pre"></span>//之前我写成了count[i]++,被hack了count[i]+=count[j];}//递增子序列个数只有本身的需特殊处理if(count[i]==0)count[i]=1;//printf("dp[%d] : %d ",i,dp[i]);}max=1;c=1;//统计最长递增子序列个数for(i=2;i<=N;i++){if(dp[max]==dp[i])c++;if(dp[max]<dp[i]){max=i;c=1;}}//最长的比1大,或最长的有多个路径if(count[max]>1 || c>1)printf("%d\n",dp[max]);elseprintf("%d\n",dp[max]-1);/*printf("c:%d,count[max]:%d\n",c,count[max]);for(i=1;i<=N;i++){printf("dp[%d]:%d ",i,dp[i]);}*/}return 0;}
0 0
- HDOJ 5087 Revenge of LIS II DP
- HDOJ-5087-Revenge of LIS II
- 【BestCoder】 HDOJ Revenge of LIS II
- Revenge of LIS II (hdu 5087 LIS)
- hdu 5087 Revenge of LIS II(LIS)
- HDOJ 题目5087 Revenge of LIS II(第二长LIS)
- hdu 5087 Revenge of LIS II dp
- 【DP】 HDU 5087 Revenge of LIS II
- HDU - 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II
- Revenge of LIS II(HDU 5087)
- HDU 5087 Revenge of LIS II
- hdoj 5087 Revenge of LIS II 【第二长单调递增子序列】
- HDOJ 5087 Revenge of LIS II (次大递增子序列)
- hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)
- hdu 5087 Revenge of LIS II(LIS,思路)
- HDU5087 Revenge of LIS II
- 淘宝知识精选
- 去掉DEDECMS5.7默认友情链接“织梦链”的方法
- ajax传入参数时post提交出错
- const指针和指向const对象的指针
- HDOJ 5088 Revenge of Nim II 位运算
- HDOJ-5087-Revenge of LIS II
- 第十周项目一(1)填充程序并使其运行十次
- 利用Python可视化MINIST数据集
- 程序员应该知道的97件事——读书笔记1(Bug与部署)
- XP蓝屏问题解决
- 判断网络是否连接方法小结(C#)
- ASI详解
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- 更改MMS协议的默认播放器