Ultraviolet A 1350-Pinary (dp + count)

Source: Internet
Author: User

Link: Ultraviolet A 1350-Pinary

N is given, n is output to Pinary Number, and Pinary Number is binary, and there is no continuous connection between two 1 s.

Solution: dp [I] indicates that there are dp [I] types in the I-th bit. Therefore, if a layer of n is given and the dp [I] is less than or equal to n, 1 is output, n minus dp [I]. Note that leading 0 cannot be output when 0 is output.

# Include

  
   
# Include

   
    
Typedef long ll; const int N = 50; ll dp [N]; void init () {memset (dp, 0, sizeof (dp )); dp [0] = dp [1] = 1; for (int I = 2; I <= 40; I ++) dp [I] = dp [I-1] + dp [I-2];} void solve (ll n) {bool flag = false; for (int I = 40; I --) {if (n> = dp [I]) {printf ("1"); n-= dp [I]; flag = true;} else if (flag) printf ("0");} printf ("\ n");} int main () {init (); int cas; ll n; scanf ("% d ", & cas); for (int I = 0; I <cas; I ++) {scanf ("% lld", & n); solve (n );} return 0 ;}

   

  

Related Article

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.