Topcoder SRM655 DIV2 950 nineeasy-pressure + digital DP

Source: Internet
Author: User

Test instructions: For you to construct an n-bit number, give you M (1-5) inquiry, each time asking for a number of digits to make up a new number and this number%9 = = 0, ask you to satisfy the number of the M query (allow prefix 0).

Problem-solving ideas: The pressure of each case to get a maximum of 9x9x9x9x9, and then according to each number of questions determine the state transfer equation.

Problem Solving Code:

1 //BEGIN CUT here2 /*3 4 */5 //END CUT here6 #line7 "NineEasy.cpp"7#include <cstdlib>8#include <cctype>9#include <cstring>Ten#include <cstdio> One#include <cmath> A#include <algorithm> -#include <vector> -#include <string> the#include <iostream> -#include <sstream> -#include <map> -#include <Set> +#include <queue> -#include <stack> +#include <fstream> A#include <numeric> at#include <iomanip> -#include <bitset> -#include <list> -#include <stdexcept> -#include <functional> -#include <utility> in#include <ctime> - using namespacestd; to  + #definePB push_back - #defineMP Make_pair the  * #defineREP (I,n) for (i=0;i< (n); ++i) $ #definefor (i,l,h) for (i= (l); i<= (h); ++i)Panax Notoginseng #defineFORD (i,h,l) for (i= (h); i>= (L); -  thetypedef vector<int>VI; +typedef vector<string>VS; Atypedef vector<Double>VD; thetypedefLong LongLL; +typedef pair<int,int>PII; -  $ #defineM 1000000007 $ Const intMaxs =9*9*9*9*9*2; -  - Long Longdp[maxs][ -]; the Long Longpow9[6]; - Wuyi classNineeasy the { -          Public: Wu         intCountintM, Vector <int>d) -         { AboutMemset (DP,0,sizeof(DP)); $pow9[0] =1; for(inti =1; I <=5; i + +) pow9[i] = pow9[i-1] *9 ;  -             intn =d.size (); -dp[0][0] =1;  -              for(inti =0; i < n; i + +){ A                  for(intj =0; J < Pow9[m]; J + +){                     +                    for(intp =0;p <=9; P + +){ the                     intNS =0;  -                      for(ints =0; s < m; S + +){ $                         if((1<< s) &D[i]) { theNS + = ((J/pow9[s] + p)%9)*Pow9[s];  the}Else{ theNS + = ((J/pow9[s])%9)*Pow9[s]; the                         } -                     } indp[ns][i+1] = (dp[ns][i+1] + dp[j][i])%M; the                   } the                 } About             } the             returndp[0][n]; the         } the          + //BEGIN CUT here -      Public: the     voidRun_test (intcase) {if(Case = =-1) || (Case = =0)) Test_case_0 ();if(Case = =-1) || (Case = =1)) Test_case_1 ();if(Case = =-1) || (Case = =2)) test_case_2 ();if(Case = =-1) || (Case = =3)) Test_case_3 ();if(Case = =-1) || (Case = =4) ) test_case_4 (); }Bayi     Private: theTemplate <typename t>stringPrint_array (ConstVector<t> &v) {ostringstream os; OS <<"{ "; for(TypeName Vector<t>::const_iterator iter = V.begin (); ITER! = V.end (); ++iter) OS <<'\"'<< *iter <<"\","; OS <<" }";returnos.str ();} the     voidVerify_case (intCase,Const int&expected,Const int&received) {Cerr <<"Test Case #"<< Case <<"...";if(expected = = Received) Cerr <<"PASSED"<< Endl;Else{Cerr <<"FAILED"<< Endl; Cerr <<"\texpected: \ ""<< expected <<'\"'<< Endl; Cerr <<"\treceived: \ ""<< Received <<'\"'<<Endl;} } -     voidTest_case_0 () {intARG0 =2;intArr1[] = {1,2}; Vector <int> Arg1 (Arr1, ARR1 + (sizeof(ARR1)/sizeof(arr1[0])));intARG2 =4; Verify_case (0, Arg2, Count (Arg0, ARG1)); } -     voidTest_case_1 () {intARG0 =2;intArr1[] = {3,3}; Vector <int> Arg1 (Arr1, ARR1 + (sizeof(ARR1)/sizeof(arr1[0])));intARG2 = A; Verify_case (1, Arg2, Count (Arg0, ARG1)); } the     voidTest_case_2 () {intARG0 =2;intArr1[] = {1,3,2}; Vector <int> Arg1 (Arr1, ARR1 + (sizeof(ARR1)/sizeof(arr1[0])));intARG2 = -; Verify_case (2, Arg2, Count (Arg0, ARG1)); } the     voidTest_case_3 () {intARG0 =5;intArr1[] = {1,2,4,8, -, -, -, +, -, +, A, at, -, -, -, -, -, in, -, to}; Vector <int> Arg1 (Arr1, ARR1 + (sizeof(ARR1)/sizeof(arr1[0])));intARG2 =893703876; Verify_case (3, Arg2, Count (Arg0, ARG1)); } the     voidTest_case_4 () {intARG0 =1;intArr1[] = {0,0,1}; Vector <int> Arg1 (Arr1, ARR1 + (sizeof(ARR1)/sizeof(arr1[0])));intARG2 = $; Verify_case (4, Arg2, Count (Arg0, ARG1)); } the  - //END CUT here the  the }; the 94 //BEGIN CUT here the intMain () the { the Nineeasy ___test;98___test.run_test (-1); About         return 0; - }101 //END CUT here
View Code

Topcoder SRM655 DIV2 950 nineeasy-pressure + digital DP

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.