uva12627 erratic expansion

Piotr found a magical box in heaven. Its magic power is that if you
place any red balloon inside it then, after one hour, it will multiply
to form 3 red and 1 blue colored balloons. Then in the next hour, each
of the red balloons will multiply in the same fashion, but the blue
one will multiply to form 4 blue balloons. This trend will continue
inde nitely. The arrangements of the balloons after the 0-th, 1-st,
2-nd and 3-rd hour are depicted in the following diagram. As you can
see, a red balloon in the cell ( i; j ) (that is i
-th row and j
-th column) will multiply to produce 3 red balloons in the cells ( i 2

cnt(i,j)表示第i分钟后上j行的红气球数。
分类讨论进行递推即可。
注意边界条件。
不用求出来所有状态,用搜索比动规好。

#include<cstdio>
long long pow[35];
long long cnt(long long k,long long p)
{
    if (p==0) return 0;
    if (k==0) return 1;
    long long x=1<<(k-1);
    if (p>=x) return 2*pow[k-1]+cnt(k-1,p-x);
    return 2*cnt(k-1,p);
}
int main()
{
    long long a,b,i,j,k,m,n,p,q,y,z;
    int T,x;
    scanf("%d",&T);
    x=0;
    pow[0]=1;
    for (i=1;i<=33;i++)
      pow[i]=pow[i-1]*3;
    while (T--)
    {
        x++;
        scanf("%lld%lld%lld",&k,&a,&b);
        printf("Case %d: %lld\n",x,cnt(k,b)-cnt(k,a-1));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值