[Digital DP] bzoj 3209 the number of flowers and gods

Source: Internet
Author: User

Question: Chinese.

Idea: like the common digit DP, convert it to binary here and record several items,

Just multiply the statistics.

Code:

# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "stack" # include "algorithm" # include "iostream" using namespace STD; long long DP [66] [66]; int M = 10000007; int num [66]; long DFS (INT site, int N, int F) {If (Site = 0) return n? N: 1; // note that it is the product, so 1 If (! F & DP [site] [N]! =-1) return DP [site] [N]; int Len = f? Num [site]: 1; long ans = 1; // The initial value of ANS is 1 for (INT I = 0; I <= Len; I ++) {if (I = 0) ans * = DFS (site-1, n, F & I = Len); else ans * = DFS (site-1, n + 1, F & I = Len); If (ANS> = m) ans % = m;} If (! F) DP [site] [N] = ans % m; return ans % m;} long solve (long x) {int CNT = 0; while (X) {num [++ CNT] = x % 2; X/= 2;} return DFS (CNT, 0, 1) % m;} int main () {long N; memset (DP,-1, sizeof (DP); While (scanf ("% LLD", & N )! =-1) {printf ("% LLD \ n", solve (n);} return 0 ;}


[Digital DP] bzoj 3209 the number of flowers and gods

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.