2016 Al-Baath University Training Camp Contest-1 J
2016-11-09 23:54
519 查看
Description
Xisfightingbeastsintheforest,inordertohaveabetterchancetosurvivehe'sgonnabuyupgradesforhisweapon.Weaponupgradeshopsareavailablealongtheforest,therearenshops,wheretheithofthemprovidesanupgradewithenergyai.UnfortunatelyXcanmakeuseonlyofthemaximumpoweroftwothatdividestheupgradeenergy,letscallitthepowerincrement.Forexample,anupgradewithenergyof6hasapowerincrementof1because6isdivisibleby21butnotdivisibleby22ormore,whileforupgradewithenergyof5powerincrementis0,alsoafterbuyingaweaponwithenergyv,Xcanonlybuyupgradeswithenergiesgreaterthanv,inotherwords,theupgradesenergiesthatXisgonnabuyshouldbeinstrictlyincreasingorder.Xiswonderingwhatisthemaximumpowerhecanachieveattheendofhisjourney.notethatonlytheenergyofupgradesshouldbeinstrictlyincreasingordernotthepowerincrementoftheupgrade.1 < n < 100,1 ≤ ai ≤ 106
Input
Thefirstlineofinputcontainsoneinteger,T,whichdenotesnumberoftestcases.Eachtestcasecontainstwolines,thefirstonecontainsoneintegernwhichdenotesnumberofshops,andthenextlinecontainsnintegerstheithofthemdenotestheenergyoftheupgradeprovidedbytheithshop.
Output
PrintoneintegerdenotesmaximumpowerXcanachieveattheendofhisjourney
Example
input
output
#include<bits/stdc++.h>
usingnamespacestd;
inta[10000],b[10000];
intdp[10000];
intmain()
{
intt;
cin>>t;
while(t--)
{
memset(dp,0,sizeof(dp));
intn;
cin>>n;
for(inti=1;i<=n;i++)
{
intnum=0;
intsum=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(inti=1;i<=n;i++)
{
for(intj=0;j<i;j++)
{
if(a[i]>a[j])
{
dp[i]=max(dp[i],b[i]+dp[j]);
}
}
}
intans=0;
for(inti=1;i<=n;i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
}
return0;
}
Xisfightingbeastsintheforest,inordertohaveabetterchancetosurvivehe'sgonnabuyupgradesforhisweapon.Weaponupgradeshopsareavailablealongtheforest,therearenshops,wheretheithofthemprovidesanupgradewithenergyai.UnfortunatelyXcanmakeuseonlyofthemaximumpoweroftwothatdividestheupgradeenergy,letscallitthepowerincrement.Forexample,anupgradewithenergyof6hasapowerincrementof1because6isdivisibleby21butnotdivisibleby22ormore,whileforupgradewithenergyof5powerincrementis0,alsoafterbuyingaweaponwithenergyv,Xcanonlybuyupgradeswithenergiesgreaterthanv,inotherwords,theupgradesenergiesthatXisgonnabuyshouldbeinstrictlyincreasingorder.Xiswonderingwhatisthemaximumpowerhecanachieveattheendofhisjourney.notethatonlytheenergyofupgradesshouldbeinstrictlyincreasingordernotthepowerincrementoftheupgrade.1 < n < 100,1 ≤ ai ≤ 106
Input
Thefirstlineofinputcontainsoneinteger,T,whichdenotesnumberoftestcases.Eachtestcasecontainstwolines,thefirstonecontainsoneintegernwhichdenotesnumberofshops,andthenextlinecontainsnintegerstheithofthemdenotestheenergyoftheupgradeprovidedbytheithshop.
Output
PrintoneintegerdenotesmaximumpowerXcanachieveattheendofhisjourney
Example
input
2 3 11016 2 812
output
5 5 题意:商店有ai的能量,主角升级按照ai能被2^n的整除(n要最大)(比如8可以被8整除(2^3),则升级3级),而且获得的能量是递增的(也就是如果810712,如果选了8,以后7就不能选了) 最多能升级多少 解法:一开始我们就固定最大值,比如固定8为最大值,算出加到8可以升级多少(这里它是第一个则计算自己),然后固定10,最后固定12 dp[i]=max(dp[i],dp[j]+b[i])(i是计算到自己时一共能升级多少,j<i且相加按照a[i]>a[j]的顺序)
相关文章推荐
- 2016 Al-Baath University Training Camp Contest-1
- 2016 Al-Baath University Training Camp Contest-1(gym101028)
- 2016 Al-Baath University Training Camp Contest-1 D
- 2016 Al-Baath University Training Camp Contest-1(gym101028)
- 2016 Al-Baath University Training Camp Contest-1 A
- 2016 Al-Baath University Training Camp Contest-1 E
- 2016 Al-Baath University Training Camp Contest-1
- 2016 Al-Baath University Training Camp Contest-1 F
- 2016 Al-Baath University Training Camp Contest-1
- 2016 Al-Baath University Training Camp Contest-1 B
- 2016 Al-Baath University Training Camp Contest-1 G
- 2016 Al-Baath University Training Camp Contest-1 C
- 2016 Al-Baath University Training Camp Contest-1 H
- 2016 Al-Baath University Training Camp Contest-1 I. March Rain —— 二分
- 2016 Al-Baath University Training Camp Contest-1 I
- Codeforce 2016 Al-Baath University Training Camp Contest-1
- 2016 Multi-University Training Contest 1 1001 hdu 5723 DFS+并查集最小生树
- 2016 Multi-University Training Contest 1 1004 GCD
- 2016 Multi-University Training Contest 1 1005 Necklace
- 2016 Multi-University Training Contest 1-1004---HDU 5726 GCD