Bzoj 1072 [SCOI2007] Arrange Perm

Source: Internet
Author: User

Considering the length of S is particularly small, only 10, you can consider the pressure DP.

Set F[s][d] means that all the positions in the set S (denoted by a binary press) are selected, and the result of D modulo is the total number of schemes of D; It is not difficult to think of transfer and initialization.

Initialization: F[0][0]=1 0 represents an empty collection here

Transfer: f[s][(d * + s[i]-' 0 ')% d]=sum{f[s0][d]} S0 is a subset of s and just one element less than s

Note that the number of repetitions is calculated more than once. There are examples. So the final answer is divided by the factorial of the number of repetitions.

Look at the code and you know it.

(Add a topic to be used in the form of pressure-pressing techniques, especially in the case of the pressure DP topic: When S ' is a true subset of S, there must be S ' <s. This allows you to determine the order of the enumerations at DP time. )

#include <cstdio>#include<cstring>#include<iostream>using namespacestd;Constsize_t Max_len ( -);Constsize_t Max_d (1050);Constsize_t Max_bit ( the); unsignedintt;unsignedintd;unsignedintLen;Charstr[max_len];unsignedintf[max_bit][max_d];unsignedintcnt[Ten];intMain () {CIN>>T;  while(t--) {memset (F,0,sizeof(F)); memset (Cnt,0,sizeof(Cnt)); CIN>> Str >>D; Len=strlen (STR);  for(unsignedinti =0; I! = len;++i)++cnt[str[i]-'0']; f[0][0] =1;  for(unsignedintS =1; S < (1<< Len); + +S) for(unsignedinti =0; I < len;++i)if(S & (1<<i)) for(unsignedintD =0;d < d;++d) f[s][(d*Ten+ Str[i]-'0')% D] + = f[s ^ (1<<i)]        [d]; unsignedint&ans = f[(1<< Len)-1][0];  for(unsignedinti =0; I! =Ten;++i) for(unsignedintg =2; G <= cnt[i];++g) Ans/=G; cout<< Ans <<Endl; }        return 0;}
Bzoj 1072

Bzoj 1072 [SCOI2007] Arrange Perm

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.