ZOJ 3923 Handshakes
2016-04-11 10:08
417 查看
水题。
算一下每个人和之前的人握手次数+之后的人和这个人握手次数。取最大值。
算一下每个人和之前的人握手次数+之后的人和这个人握手次数。取最大值。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=100000+10; int n; int a[maxn],dp[maxn]; int main() { int T; scanf("%d",&T); while(T--) { scanf("%d",&n); int ans=0; for(int i=1; i<=n; i++) scanf("%d",&a[i]); dp[n+1]=0; for(int i=n; i>=1; i--) { if(a[i]==0) dp[i]=dp[i+1]; else dp[i]=dp[i+1]+1; } for(int i=1; i<=n; i++) ans=max(ans,dp[i+1]+a[i]); printf("%d\n",ans); } return 0; }
相关文章推荐
- 浅谈php字符串
- Zookeeper 安装和配置---学习三
- 关于如何提高研发部门工作效率的探讨
- 在shell脚本中调用另一个脚本的三种不同方法(fork, exec, source)
- 判断List、Map、Set是否为空及效率比较
- jQuery基础事件
- Android AIDL学习
- Gradle compile依赖jar,GroupId,ArtifactId查询
- 京东2016笔试题,小东复习
- HTML5常用标签
- 解决几个编译警告我和错误问题
- SecureCRT 7.3.4破解版(含注册机)
- 小米3手机重置
- Glide用在CircleImageView上每次进入第一次显示默认图片
- MVC5中路由新特性
- Redis 快速入门
- 从HAL层到java应用层重写mini6410 led功能
- DNS的解析,gethostbyname的弊端
- 【剑指offer系列】 二叉树的深度___39
- revoke回收权限的小问题