2016 Al-Baath University Training Camp Contest-1 J

Description

X is fighting beasts in the forest, in order to have a better chance to survive he's gonna buy upgrades for his weapon. Weapon upgrade shops are available along the forest, there are n shops, where the ith of them provides an upgrade with energy ai. Unfortunately X can make use only of the maximum power of two that divides the upgrade energy, lets call it the powerincrement. For example, an upgrade with energy of 6 has a power increment of 1 because 6 is divisible by 21 but not divisible by 22 or more, while for upgrade with energy of 5 power increment is 0, also after buying a weapon with energy v, X can only buy upgrades with energies greater than v, in other words, the upgrades energies that X is gonna buy should be in strictly increasing order. X is wondering what is the maximum power he can achieve at the end of his journey. note that only the energy of upgrades should be in strictly increasing order not the power increment of the upgrade. 1 < n < 100, 1 ≤ ai ≤ 106

Input

The first line of input contains one integer, T, which denotes number of test cases. Each test case contains two lines, the first one contains one integer n which denotes number of shops, and the next line contains n integers the ith of them denotes the energy of the upgrade provided by the ith shop.

Output

Print one integer denotes maximum power X can achieve at the end of his journey

Example
input
2
3
1 10 16
2
8 12
output
5
5
题意:商店有ai的能量,主角升级按照ai能被2^n的整除(n要最大)(比如8可以被8整除(2^3),则升级3级),而且获得的能量是递增的(也就是如果 8 10 7 12,如果选了8,以后7就不能选了)
最多能升级多少
解法:一开始我们就固定最大值,比如固定8为最大值,算出加到8可以升级多少(这里它是第一个则计算自己),然后固定10,最后固定12
dp[i]=max(dp[i],dp[j]+b[i])(i是计算到自己时一共能升级多少,j<i且相加按照a[i] > a[j]的顺序)
#include<bits/stdc++.h>
using namespace std;
int a[10000],b[10000];
int dp[10000];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            int num=0;
            int sum=1;
            cin>>a[i];
            while(a[i]%sum==0)
            {
                num++;
                sum*=2;
            }
            b[i]=num-1;
            dp[i]=num-1;
           // cout<<num-1<<endl;
        }
        for(int i = 1;i <= n;i++)
        {
            for(int j = 0;j < i;j++)
            {
                if(a[i] > a[j])
                {
                    dp[i] = max(dp[i],b[i] + dp[j]);
                }
            }
        }
        int ans=0;
        for(int i=1; i<=n; i++)
            ans=max(ans,dp[i]);
        printf("%d\n",ans);
    }
    return 0;
}

  

 

转载于:https://www.cnblogs.com/yinghualuowu/p/6049369.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值