CF587A.Duff and Weight Lifting
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2_w__i_ pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.

Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2_a_1, ..., 2_a__k_ if and only if there exists a non-negative integer x such that 2_a_1 + 2_a_2 + ... + 2_a__k_ = 2_x_, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
最近,达芙一直在练习举重。作为一项艰苦的训练,马莱克给她布置了一项任务:他给了她一个重量序列,其中第 i 个重量为 2wi 磅。在每一步中,达芙可以举起当前剩余重量中的若干个,并将它们扔掉。她重复这一过程,直到所有重量都被扔完。马莱克要求她使总步数最小。

达芙是一名竞技编程爱好者。因此,在每一步中,她只能举起并扔掉一个重量序列 2a1,…,2ak,当且仅当存在一个非负整数 x,使得 2a1+2a2+⋯+2ak=2x,即这些数的和本身是一个 2 的幂。
达芙虽是竞技编程爱好者,却并非程序员。因此她向你求助,请你帮她使总步数最小。
输入格式
The first line of input contains integer n (1 ≤ n ≤ 106), the number of weights.
The second line contains n integers _w_1, ..., w__n separated by spaces (0 ≤ w__i ≤ 106 for each 1 ≤ i ≤ n), the powers of two forming the weights values.
输入的第一行包含一个整数 n(1 ≤ n ≤ 106),表示砝码的数量。
第二行包含 n 个由空格分隔的整数 w1, …, wn(对每个 1 ≤ i ≤ n,满足 0 ≤ wi ≤ 106),这些是构成砝码重量的 2 的幂次。
输出格式
Print the minimum number of steps in a single line.
输出最少步数,占一行。
输入输出样例
输入#1
5 1 1 2 3 3
输出#1
2
输入#2
4 0 1 2 3
输出#2
4
说明/提示
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
在第一个样例中:一种最优方案是在第一步丢弃前三个砝码,在第二步丢弃剩余的砝码。无法仅用一步完成,因为它们的总和不是 2 的幂。
在第二个样例中:唯一的最优方案是每步丢弃一个砝码。无法用少于 4 步完成,因为不存在包含多于一个砝码且总和为 2 的幂的砝码子集。
输入解题思路,AI测评打分。不知道怎么写?