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;
}

  

 

2016 Al-Baath University Training Camp Contest-1 J的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest)

    2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest) Problem A. M ...

  3. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  4. 2016 Al-Baath University Training Camp Contest-1 B

    Description A group of junior programmers are attending an advanced programming camp, where they lea ...

  5. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  6. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  7. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  8. 2016 Al-Baath University Training Camp Contest-1 G

    Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...

  9. 2016 Al-Baath University Training Camp Contest-1 F

    Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...

随机推荐

  1. 转:python webdriver API 之设置等待时间

    有时候为了保证脚本运行的稳定性,需要脚本中添加等待时间.sleep(): 设置固定休眠时间. python 的 time 包提供了休眠方法 sleep() , 导入 time 包后就可以使用 slee ...

  2. Python学习总结16:时间模块datetime & time & calendar (三)

    calendar模块 常见函数及说明 1 calendar.calendar(year,w=2,l=1,c=6)   返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c. 每日宽度间隔为 ...

  3. Java基础(38):Calendar类的应用(优于Date类)

    Calendar 类的应用 Date 类最主要的作用就是获得当前时间,同时这个类里面也具有设置时间以及一些其他的功能,但是由于本身设计的问题,这些方法却遭到众多批评,不建议使用,更推荐使用 Calen ...

  4. 在Tomcat里使用配置连接池连接数据库

    一:首先在Tomcat下的conf/context.xml文件里的contenx标签里配置数据源: <Resource name="jdbc/zzz" auth=" ...

  5. 在GitHub上建立个人主页的方法(转载)

    GitHub就不需要介绍了,不清楚可以百度一下.只说目前GitHub是最火的开源程序托管集中地了,连PHP的源码都在GitHub上面托管了(https://github.com/php ). GitH ...

  6. 夺命雷公狗—angularjs—16—angularjs里面的缓存

    强大的angularjs也给我们预留了一套他的缓存机智,这样在某个程度上来说还是可以做到减轻一点服务器压力的.... <!DOCTYPE html> <html lang=" ...

  7. 夺命雷公狗---node.js---11之文件上传

    我们在做文件上传前需要用npm来安装一个插件先, 首先打开项目所在的目录,然后按住shift键然后右键鼠标进入命令行安装formidable 然后开始编写上传的静态页面: <!DOCTYPE h ...

  8. TVideoGrabber的使用(一)捕捉摄像头

    使用TVideoGrabber捕捉摄像头,相当容易,只需几句代码即可解决问题,首先我们新建一个工程,然后从控件面板上拉取一个 TVideoGrabber控件到窗体中,然后再在窗体上放置四个Button ...

  9. 数据库订正脚本性能优化两则:去除不必要的查询和批量插入SQL

    最近在做多数据库合并的脚本, 要将多个分数据库的表数据合并到一个主数据库中. 以下是我在编写数据订正脚本时犯过的错误, 记录以为鉴. 不必要的查询 请看以下语句: regiondb = db.Houy ...

  10. Delphi XE的firemonkey获取当前文件所在路径的方法

    Delphi XE的firemonkey获取当前文件所在路径的方法 在之前,我们知道有三种方法: ExtractFilePath(ParamStr(0)) ExtractFilePath(Applic ...