UVALive
来源:互联网 发布:公司美工属于什么部门 编辑:程序博客网 时间:2024/06/16 04:50
题目链接
思路:水dp,记录每一个数其上一个相同数的前驱,对于新来的这个数,如果前面有这个数出现过,那么就可以得分,并维护该点得分与不得分的与前面的最大值.
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+10;int pre[maxn],dp[maxn];int main(){int n;while(scanf("%d",&n)!=EOF){if(n==0)break;int x;memset(dp,0,sizeof(dp));memset(pre,-1,sizeof(pre));for(int i=1;i<=n;i++){scanf("%d",&x);if(pre[x]!=-1){if(x==999)dp[i]=max(dp[i-1],dp[pre[x]]+3);elsedp[i]=max(dp[i-1],dp[pre[x]]+1);}elsedp[i]=dp[i-1];pre[x]=i;//注意更新pre的值,,,这wa了一次....}printf("%d\n",dp[n]);}}
0 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 轻松搞定瑜伽微信公众号预约
- 图像处理matlab基础
- Ubuntu中.deb包的安装与卸载异常处理
- Python十分钟总结知识点
- php操作redis
- UVALive
- Java并发
- 阿里巴巴助攻腾讯破6.2亿微商传销第一大案!涉案公众号粉丝2400
- #9 (Div. 2 Only) E. Interesting Graph and Apples (并查集+构造图)
- 有序广播和无序广播
- JDBC干货篇一
- MYSQL 业务查询
- React/React Native 的ES5 ES6写法对照
- java集合