hdu 2825 Wireless Password (ac自动机+状压dp)

题意:

给出m个串,现在一个n个字母的字句里面必须包含至少p个m集合中的串。问有多少种方式。

题解:

kuangbin说ac自动机状态转移图什么,不是很懂。但是抛开这个,去思考也是可以做的。我们在ac自动机上dp肯定要设置这样的状态dp[i][j]走了i步,结尾是j节点,但是这样明显无法获得由几m集合中的串,分析发现这类似排列组合,要实现这样的计数问题,只能是状压dp,那么我们多设置一维dp[i][j][s]s表示获得m集合中串的状态。最后只要得到状态中1个数大于p的答案就好。


#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define B(x) (1<<(x))
typedef long long ll;
const int oo=0x3f3f3f3f;
const ll OO=1LL<<61;
const ll MOD=20090717;
const int maxn=1005;
const int SIZE=110;
char str[maxn];
int dp[27][SIZE][B(10)+5];
int num[B(10)+5];

struct AC
{
    int next[SIZE][26],fail[SIZE],end[SIZE],Q[SIZE*26];
    int root,cnt;

    void Init()
    {
        cnt=0;
        root=newNode();
    }

    int newNode()
    {
        for(int i=0;i<26;i++)
            next[cnt][i]=-1;
        end[cnt++]=0;
        return cnt-1;
    }

    void Insert(char buff[],int id)
    {
        int now=root;
        int len=strlen(buff);
        for(int i=0,k;i=p)
                for(int i=0;i



你可能感兴趣的:(字符串—ac自动机,字符串)