hdu 5773 The All-purpose Zero
2016-07-28 22:35
225 查看
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=100005; const int inf=0x3f3f3f3f; int kase, n, cnt; int sum[maxn], a[maxn], num[maxn], dp[maxn]; void print() { for (int i=0; i<n; i++) printf("%d%c", sum[i], i==n-1?'\n':' '); } void print2() { for (int i=0; i<cnt; i++) printf("%d%c", num[i], i==cnt-1?'\n':' '); } int main() { //freopen("in.txt", "r", stdin); scanf("%d", &kase); for (int cas=1; cas<=kase; cas++) { memset(sum, 0, sizeof(sum)); scanf("%d", &n); for (int i=0; i<n; i++) scanf("%d", &a[i]); for (int i=0; i<n; i++) if (a[i]==0) sum[i]=1; for (int i=1; i<n; i++) sum[i]+=sum[i-1]; cnt=0; for (int i=0; i<n; i++) if (a[i]!=0) num[cnt++]=a[i]-sum[i]; memset(dp, 0x3f, sizeof(dp)); for (int i=0; i<cnt; i++) *lower_bound(dp, dp+n, num[i])=num[i]; printf("Case #%d: %d\n", cas, sum[n-1]+(int)(lower_bound(dp, dp+n, inf)-dp)); } return 0; }
相关文章推荐
- 二叉查找树
- 使用Spring MVC构建Web应用程序
- 2016.02.16我的上司对我说的一席话
- 造成远程文件大小为零的原因(索引值里变成了0)
- coffeeScript中类的多态[学习篇]
- SVG学习笔记(2)
- poj2376(Cleaning Shifts)贪心算法
- leetcode题解日练--2016.7.28
- 怎样将word中拼写错误的下划线去掉——有方法
- Hash算法
- F28027第四节课---中断
- IOS学习之核心动画-音乐震动条
- 【Java】Hashmap不能用基本的数据类型 Dimensions expected after this token
- Codeforces Beta Round #87 (Div. 1 Only)B Lawnmower(贪心)
- Codeforces Beta Round #87 (Div. 1 Only)B Lawnmower(贪心)
- STL vector的模拟实现
- 文件、目录管理相关命令
- java面试题3--成员内部类的面试题
- Mysql数据库基本操作
- 类加载机制