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
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.
Print one integer denotes maximum power X can achieve at the end of his journey
2
3
1 10 16
2
8 12
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的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 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 ...
- 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 ...
- 2016 Al-Baath University Training Camp Contest-1 B
Description A group of junior programmers are attending an advanced programming camp, where they lea ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- [原创]java WEB学习笔记48:其他的Servlet 监听器:域对象中属性的变更的事件监听器 (3 个),感知 Session 绑定的事件监听器(2个)
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- [Linux]可用于管道操作的命令
管道命令——| command1 | command2 | command3 注:管道命令必须能够接受来自前一个命令的数据成为standard input继续处理. cut 将一段信息的某一段切出来, ...
- qlserver、Mysql、Oracle三种数据库的优缺点总结
这篇文章主要介绍了sqlserver.Mysql.Oracle三种数据库的优缺点总结,需要的朋友可以参考下 一.sqlserver优点:易用性.适合分布式组织的可伸缩性.用于决策支持的数据仓库功能 ...
- Axis2、Axis1 以及其他接口的调用方式
在请求的时候出现问题,使用下面的方式请求就不会出现问题. package webservice.client.utils; import java.util.Iterator; import java ...
- 【py】安装ipython-notebook
os:ubunutu(debian)-based linux 分两步: 安装ipython及其依赖包 sudo apt-get install ipython-notebook 安装可选的附加工具 ...
- 由Unicode编码想到弄懂编码表
test unicode好 007400650073007400200075006E00690063006F00640065597D 这是一个Unicode编码,一共六七万的汉字,可以说Unicode ...
- hadoop 启动停止命令
1 批量启动与停止 1.1 Start-all.sh # Start all hadoop daemons. Run this on master node. bin=`dirname ...
- IT书籍的选择与阅读
拍摄是一件艰苦而有趣的事情. 它需要眼睛和心灵完全融合投入, 需要耐心等待排除干扰, 需要敏捷捕捉稍纵即逝的瞬间. 但是, 非艰苦不成乐趣. 人生也应该选择一件有难度的事情来做. 做不成, 可以收获过 ...
- ftp 终端命令
近期使用 macbook,并与新买的路由器折腾, 先备着... http://blog.csdn.net/qinde025/article/details/7595102 ftp使用的内部命令如下(其 ...
- 161206、 Ionic、Angularjs、Cordova搭建Android开发环境
1.jdk 环境变量配置 path:C:\Program Files\Java\jdk1.7.0_79\bin 2.Node.js 因为安装cordova时要用到node.js的npm 下载地址: h ...