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. interesting js

    [‎5/‎3/‎2016 4:18 PM] Calos Chen: function a(b,e){var a=0;a+=b;if(e){console.log(b+e);return;} retur ...

  2. extjs 4.2 日期控件 选择时分秒功能

    因为不支持时分秒,然后在网上也找了一段时间的插件,但是感觉起来都不大方便,最后找一个插件,只需要引用js文件,然后修改类型,就可以实现extjs下面的datafield带时分秒功能了. 步骤: 只需要 ...

  3. android studio ADB not responding.

    打开cmd    输入  netstat -aon|findstr "5037"   找到谁在占用5037端口 记住他的pid. 例如pid为 2028 输入  taskkill ...

  4. WEB-INF/views/menu/list.jsp (line: 26, column: 58) equal symbol expected

    根本原因是由于单引号和双引号的混乱使用导致的. 解决办法: 将双引号里面的双引号改成单引号: 单引号里面的双引号该成单引号. 我的问题好像又不是这样的,<c:forEach var=" ...

  5. 夺命雷公狗---DEDECMS----25dedecms导航条首页的跳转

    我们的导航条首页一直没写跳转,现在我们看看dede自带模版的首页是怎么写的: 他也是封装了一个{dede:global.cfg_cmsurl/}/内置标签来实现的,那么我们来改下我们的head.htm ...

  6. mysql单表查询&&多表查询(职员表14+9)

    dept(deptno,dname,loc) emp(empno,ename,job,mgr,hiredate,sal,COMM,deptno) salgrade(grade,losal,hisal) ...

  7. Creater中选择一行的方法

    1.  在表布局中增加一单选钮列,给单选钮的属性name任意设定一个值.2.  选择单选钮对应列,将其selectID设为单选钮的ID;将onclick设为setTimeout('initAllRow ...

  8. Error: 16GU盘变1G,恢复

    最近装win10,chromium os之后,删除U盘中的文件,发现不能删除,脑子一热格式化了,发现16G突然变成了1G,这不是坑爹吗,刚买的新U盘呀.立马百度,发现有说是买的被骗了,有的说使用某个软 ...

  9. Spring JDBC保存枚举对象含关键字报错原因之一

    报错信息: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized S ...

  10. 5.1JavaScript精华

    9.使用Promises Promises,是Javascript表现item的一种方式.它执行异步工作,在未来的某个时间点完成.遇到最多的promises,是使用Ajax请求.浏览器在后台发起HTT ...