标签:
题目链接:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1766 Accepted Submission(s): 669
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
int l,r;
LL d,ans,dp[40];
void dfs(LL cur,int hi,int lo,int pos)
{
if(hi<=0||pos<0)return ;
if(cur>=dp[pos]){ans+=dp[pos],dfs(cur-dp[pos],hi-1,lo-1,pos-1);}
else
{
if(lo==pos+1)
{
ans+=dp[lo]-1;
return ;
}
else
{
LL num=0;
for(int i=pos-1;i>=max(0,pos-hi);i--)num+=dp[i];
if(num>cur)dfs(cur,hi,lo,pos-1);
else
{
ans+=dp[pos];
lo--;
if(lo>0)ans+=dp[lo]-1;
return ;
}
}
}
}
int main()
{
int t,Case=0;
scanf("%d",&t);
dp[0]=1;
for(int i=1;i<=33;i++)dp[i]=dp[i-1]*2;
while(t--)
{
scanf("%lld%d%d",&d,&l,&r);
ans=0;
dfs(d,r,l,32);
if(d==0)
{
if(l==0)ans=1;
else ans=dp[l]-1;
}
printf("Case #%d: %lld\n",++Case,ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5954815.html