您的位置:首页 > 大数据 > 人工智能

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
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]的顺序)


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

  


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: