日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

hdu 2825 Wireless Password AC自动机+状态DP

發(fā)布時(shí)間:2024/4/14 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 2825 Wireless Password AC自动机+状态DP 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

時(shí)間卡得緊,寫成遞推可以做一些優(yōu)化

//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define pb(a) push_back(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) {return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) {return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #elsefreopen("d:\\in.txt","r",stdin);// freopen("d:\\out1.txt","w",stdout); #endif } int getch() {int ch;while((ch=getchar())!=EOF) {if(ch!=' '&&ch!='\n')return ch;}return EOF; }const int MAX_NODE=100; const int SIGMA_SIZE=26; const int mod = 20090717;int ch[MAX_NODE][SIGMA_SIZE]; int val[MAX_NODE]; int fail[MAX_NODE]; int sz;void init() {memset(ch[0],0,sizeof(ch[0]));sz=1;val[0]=0; } int idx(char c){return c-'a';} void insert(const char *s,int k) {int u=0;for(int i=0;s[i]!='\0';i++){int v=idx(s[i]);if(!ch[u][v]){memset(ch[sz],0,sizeof(ch[sz]));val[sz]=0;ch[u][v]=sz++;}u=ch[u][v];}val[u]=1<<k; }void construct () {fail[0]=0;queue<int> q;for(int c=0;c<SIGMA_SIZE;c++){int u=ch[0][c];if(u){fail[u]=0;q.push(u);}}while(!q.empty()){int r=q.front();q.pop();for(int c=0;c<SIGMA_SIZE;c++){int u=ch[r][c];if(!u){ch[r][c]=ch[fail[r]][c];continue;}q.push(u);int v=fail[r];while(v&&!ch[v][c])v=fail[v];fail[u]=ch[v][c];val[u]|=val[fail[u]];}} }int check[1<<10]; void prework() {for(int st=0;st<(1<<10);st++){check[st]=0;int nst=st;while(nst){check[st]+=nst%2;nst/=2;}} } int dp[MAX_NODE][26][1<<10];int DP(int n,int m,int k) {memset(dp,0,sizeof(dp));dp[0][0][0]=1;for(int i=0,k=0;i<n;i++,k^=1){for(int u = 0;u<sz;u++){for(int st=0;st<(1<<m);st++)if(dp[u][i][st]>0){for(int c=0;c<SIGMA_SIZE;c++){dp[ch[u][c]][i+1][st|val[ch[u][c]]]=(dp[ch[u][c]][i+1][st|val[ch[u][c]]]+dp[u][i][st])%mod;}}}}int res=0;for(int u=0;u<sz;u++){for(int st=(1<<k)-1;st<=(1<<m);st++)if(check[st]>=k)res=(res+dp[u][n][st])%mod;}return res; } int main() {prework();int n,m,k;while(scanf("%d%d%d",&n,&m,&k)!=EOF&&(n+m+k)){init();for(int i=1;i<=m;i++){char buf[15];scanf("%s",buf);insert(buf,i-1);}construct();int res=DP(n,m,k);printf("%d\n",res);}return 0; } View Code

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/BMan/p/3415152.html

總結(jié)

以上是生活随笔為你收集整理的hdu 2825 Wireless Password AC自动机+状态DP的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。