Problem A
Accepts: 1662
Submissions: 11595
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
记hash(i)表示第一位到第i位不模9973的值,用一个前缀数组pre[i]表示前i位模9973的哈希值,那么第a-b位的哈希值hash(b)/hash(a-1),当然算的答案要模9973,所以pre[b]/pre[a-1]%9973既可,但是pre数组存放的值已经对9973取模了,所以要求一下乘法逆元然后乘上去取模就好。
代码:
#include
#include
Problem B
Accepts: 2258
Submissions: 8344
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
用dp[i]表示长度为i的序列能构造的新序列数,那么对于新增的第i个1,他要么不于前面的数合并,此时情况数为dp[i-1],要么与前面的1合并,此时的情况数为dp[i-2]
即dp[i] = dp[i-1] + dp[i-2]
i最大为200,要用下大数模板。数据有毒,0的时候直接输出空行。
代码:
#include
#include
Problem C
Accepts: 719
Submissions: 5881
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
字典树的运用,每个结点表示该前缀出现的次数。要注意删除的时候要把前缀删干净,比如删除he的时候把he heh hehe hel hell hello删了,还要把h的次数减去2才行。
代码:
#include
#include
Problem D
Accepts: 2614
Submissions: 7849
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
把名字排序一下放到map里就好了..
#include
#include