bzoj 1030

单词建出AC自动机,然后在自动机上做DP

d[i][j]表示第i个字符匹配到节点j上的方案数

直接算有点麻烦,统计不满足的方案数就好了

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 10007
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define lowbit(x) (x&(-x))
10 #define ida(x) (x-'A')
11 #define NM 100+5
12 using namespace std;
13 int read(){
14     int x=0,f=1;char ch=getchar();
15     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
16     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
17     return x*f;
18 }
19 const int cnt=25;
20 struct node{
21     node *c[cnt+1],*f;
22     bool s;
23     int id;
24 }N[100*NM],*o=N,*root;
25 node* newnode(){
26     o->id=o-N;o->f=root;o->s=0;return o++;
27 }
28 char st[NM];
29 int n,m,d[100*NM],f[100*NM],ans;
30 void ins(){
31     node *r=root;
32     scanf("%s",st);int len=strlen(st)-1;
33     inc(i,0,len){
34         if(!r->c[ida(st[i])])r->c[ida(st[i])]=newnode();
35         r=r->c[ida(st[i])];
36     }
37     r->s=true;
38 }
39 void bfs(){
40     queue<node*>q;
41     inc(i,0,cnt)if(root->c[i])q.push(root->c[i]);
42     while(!q.empty()){
43         node *t=q.front();q.pop();
44         inc(i,0,cnt)if(t->c[i]){
45             node *r=t->f;
46             while(r!=root&&!r->c[i])r=r->f;
47             t->c[i]->f=r->c[i]?r->c[i]:root;
48             if(t->c[i]->f->s)t->c[i]->s=true;
49             q.push(t->c[i]);
50         }
51     }
52 }
53 void dp(node *r){
54     if(r->s)return;
55     inc(i,0,cnt)if(r->c[i]){
56         (d[r->c[i]->id]+=f[r->id])%=inf;
57         dp(r->c[i]);
58     }else{
59         node *t=r->f;
60         while(t!=root&&!t->c[i])t=t->f;
61         if(t->c[i])(d[t->c[i]->id]+=f[r->id])%=inf;else (d[0]+=f[r->id])%=inf;
62     }
63 }
64 void dfs(node *r){
65     if(r->s)return;
66     inc(i,0,cnt)if(r->c[i])dfs(r->c[i]);
67     (ans+=inf-f[r->id])%=inf;
68 }
69 int main(){
70 //    freopen("data.in","r",stdin);
71     root=newnode();root->f=root;
72     n=read();m=read();
73     inc(i,1,n)ins();
74     bfs();ans=1;f[0]++;
75     inc(i,1,m){
76         (ans*=26)%=inf;
77         dp(root);
78         memcpy(f,d,sizeof(d));mem(d);
79 //        inc(i,0,o-N)printf("%d ",f[i]);printf("\n");
80     }
81     dfs(root);
82     printf("%d\n",ans);
83     return 0;
84 }
View Code

 

转载于:https://www.cnblogs.com/onlyRP/p/5194126.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BZOJ 2908 题目是一个数据下载任务。这个任务要求下载指定的数据文件,并统计文件中小于等于给定整数的数字个数。 为了完成这个任务,首先需要选择一个合适的网址来下载文件。我们可以使用一个网络爬虫库,如Python中的Requests库,来帮助我们完成文件下载的操作。 首先,我们需要使用Requests库中的get()方法来访问目标网址,并将目标文件下载到我们的本地计算机中。可以使用以下代码实现文件下载: ```python import requests url = '目标文件的网址' response = requests.get(url) with open('本地保存文件的路径', 'wb') as file: file.write(response.content) ``` 下载完成后,我们可以使用Python内置的open()函数打开已下载的文件,并按行读取文件内容。可以使用以下代码实现文件内容读取: ```python count = 0 with open('本地保存文件的路径', 'r') as file: for line in file: # 在这里实现对每一行数据的判断 # 如果小于等于给定整数,count 加 1 # 否则,不进行任何操作 ``` 在每一行的处理过程中,我们可以使用split()方法将一行数据分割成多个字符串,并使用int()函数将其转换为整数。然后,我们可以将该整数与给定整数进行比较,以判断是否小于等于给定整数。 最后,我们可以将统计结果打印出来,以满足题目的要求。 综上所述,以上是关于解决 BZOJ 2908 数据下载任务的简要步骤和代码实现。 希望对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值