HDU 3555 Bomb

Source: Internet
Author: User

Recently, I have been practicing the digital dp. This is still a problem of wang. This is a basic question. I have nothing to say. I have attached the code.

 

# Include <stdio. h> # include <string. h> # define LL unsigned long longLL dp [3] [30]; LL a [30]; void init () {int I, j, k; dp [0] [0] = 1; for (I = 1; I <22; I ++) {dp [0] [I] = dp [0] [I-1] * 10-dp [1] [I-1]; dp [1] [I] = dp [0] [I-1]; dp [2] [I] = dp [2] [I-1] * 10 + dp [1] [I-1];} LL solve (LL n) {int I, j, k, len; for (I = 1; n; I ++) {a [I] = n % 10; n/= 10;} len = I; a [len] = 0; LL ans = 0, flag = 0; for (I = len-1; I> 0; I --) {ans + = a [I] * dp [2] [I-1]; if (flag) ans + = a [I] * d P [0] [I-1]; else {if (a [I]> 4) ans + = dp [1] [I-1]; // here I started to write if (a [I + 1]> 4) ans + = dp [0] [I-1], wrong once ~ } If (a [I + 1] = 4 & a [I] = 9) flag = 1;} return ans;} int main () {init (); int I, j, k, t; LL n; scanf ("% d", & t); while (t --) {scanf ("% I64u", & n ); printf ("% I64u \ n", solve (n + 1);} 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.