UVA 12673 erratic Expansion strange balloon swell

Source: Internet
Author: User

It is not difficult to find that every one hours, in addition to the bottom right of the balloon is all blue, the others and one hours of the balloon is the same, so it can be recursive. Then define a similar prefix and something F (k,i) indicates the number of red balloons above I line after k hours. The total number of red balloons in the K-Hour is preprocessed by C (k), and the termination condition is observed recursively.

#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;Const intMAXN = to; ll C[maxn];ll F (intKinti) {    if(!i)return 0; if(i = = (1&LT;&LT;K))returnC[k]; inttot =1<< (K-1); if(I>tot)returnF (K-1, I-tot) + (c[k-1]<<1); Else returnF (K-1, i) <<1;}intMain () {intT scanf"%d",&T); c[0]  =1;  for(inti =1; i < MAXN; i++) C[i] = c[i-1]*3; intKas =0;  while(t--){        intK,a,b; scanf"%d%d%d",&k,&a,&b); ll ans= f (k,b)-F (k,a-1); printf ("Case %d:%lld\n",++Kas,ans); }}

UVA 12673 erratic Expansion strange balloon swell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.