HDU 3341 Lost's revenge
来源:互联网 发布:个人陈述 知乎 编辑:程序博客网 时间:2024/05/19 00:13
Problem Description
Lost and AekdyCoin are friends. They always play "number game"(A boring game based on number theory) together. We all know that AekdyCoin is the man called "nuclear weapon of FZU,descendant of Jingrun", because of his talent in the field of number theory. So Lost had never won the game. He was so ashamed and angry, but he didn't know how to improve his level of number theory.
One noon, when Lost was lying on the bed, the Spring Brother poster on the wall(Lost is a believer of Spring Brother) said hello to him! Spring Brother said, "I'm Spring Brother, and I saw AekdyCoin shames you again and again. I can't bear my believers were being bullied. Now, I give you a chance to rearrange your gene sequences to defeat AekdyCoin!".
It's soooo crazy and unbelievable to rearrange the gene sequences, but Lost has no choice. He knows some genes called "number theory gene" will affect one "level of number theory". And two of the same kind of gene in different position in the gene sequences will affect two "level of number theory", even though they overlap each other. There is nothing but revenge in his mind. So he needs you help to calculate the most "level of number theory" after rearrangement.
One noon, when Lost was lying on the bed, the Spring Brother poster on the wall(Lost is a believer of Spring Brother) said hello to him! Spring Brother said, "I'm Spring Brother, and I saw AekdyCoin shames you again and again. I can't bear my believers were being bullied. Now, I give you a chance to rearrange your gene sequences to defeat AekdyCoin!".
It's soooo crazy and unbelievable to rearrange the gene sequences, but Lost has no choice. He knows some genes called "number theory gene" will affect one "level of number theory". And two of the same kind of gene in different position in the gene sequences will affect two "level of number theory", even though they overlap each other. There is nothing but revenge in his mind. So he needs you help to calculate the most "level of number theory" after rearrangement.
Input
There are less than 30 testcases.
For each testcase, first line is number of "number theory gene" N(1<=N<=50). N=0 denotes the end of the input file.
Next N lines means the "number theory gene", and the length of every "number theory gene" is no more than 10.
The last line is Lost's gene sequences, its length is also less or equal 40.
All genes and gene sequences are only contains capital letter ACGT.
For each testcase, first line is number of "number theory gene" N(1<=N<=50). N=0 denotes the end of the input file.
Next N lines means the "number theory gene", and the length of every "number theory gene" is no more than 10.
The last line is Lost's gene sequences, its length is also less or equal 40.
All genes and gene sequences are only contains capital letter ACGT.
Output
For each testcase, output the case number(start with 1) and the most "level of number theory" with format like the sample output.
Sample Input
3ACCGGTCGAT1AAAAA0
Sample Output
Case 1: 3Case 2: 2
ac自动机+多进制状压dp
#include<stdio.h>#include<string.h>#include<queue>#include<malloc.h>using namespace std;const int maxn = 505;int n;class tire{public: tire *down[26], *next; int end, id; tire(){ next = NULL; id = end = 0; memset(down, 0, sizeof(down)); }};class ac_automaton{private: tire *root; tire *node[maxn]; int tot, pos[4], sum; int ch[4]; char s[maxn]; int f[maxn][maxn * 30];public: ac_automaton(){ node[0] = root = new tire; tot = 0; } void clear(){ node[0] = root = new tire; tot = 0; } void insert() { scanf("%s", s); tire* j = root; for (int i = 0, k; s[i]; i++) { k = s[i] - 'A'; if (!j->down[k]) { node[++tot] = j->down[k] = new tire; node[tot]->id = tot; } j = j->down[k]; } j->end++; } void getnext() { queue<tire*> p; tire *q, *k, *j; root->next = root; for (int i = 0; i < 26; i++) if (root->down[i]) { q = root->down[i]; q->next = root; p.push(q); } else root->down[i] = root; while (!p.empty()) { q = p.front(); p.pop(); k = q->next; q->end += k->end; for (int i = 0; i < 26; i++) if (q->down[i]) { j = q->down[i]; j->next = k->down[i]; p.push(q->down[i]); } else q->down[i] = k->down[i]; } } void getpos() { scanf("%s", s); ch[0] = 'A' - 'A'; ch[1] = 'C' - 'A'; ch[2] = 'G' - 'A'; ch[3] = 'T' - 'A'; memset(pos, 0, sizeof(pos)); for (int i = 0; s[i]; i++) { if (s[i] == 'A') pos[0]++; if (s[i] == 'C') pos[1]++; if (s[i] == 'G') pos[2]++; if (s[i] == 'T') pos[3]++; } sum = (pos[0] + 1) * (pos[1] + 1) * (pos[2] + 1) * (pos[3] + 1) - 1; pos[0] = (pos[1] + 1) * (pos[2] + 1) * (pos[3] + 1); pos[1] = (pos[2] + 1) * (pos[3] + 1); pos[2] = (pos[3] + 1); pos[3] = 1; } int work_out() { getnext(); getpos(); int ans = 0; memset(f, -1, sizeof(f)); f[0][sum] = 0; for (int i = sum; i >= 0; i--) { for (int j = 0; j <= tot; j++) if (f[j][i] >= 0) { int I = i; for (int k = 0; k < 4; k++) { if (I / pos[k]) { int &u = f[node[j]->down[ch[k]]->id][i - pos[k]]; u = max(u, f[j][i] + node[j]->down[ch[k]]->end); } I %= pos[k]; } ans = max(ans, f[j][i]); } } return ans; }}F;int main(){ int z = 0; while (scanf("%d", &n), n) { F.clear(); for (int i = 0; i < n; i++) F.insert(); printf("Case %d: %d\n", ++z, F.work_out()); } return 0;}
0 0
- hdu 3341 Lost's revenge
- hdu 3341 Lost's revenge
- HDU 3341 Lost's revenge
- HDU 3341Lost's revenge
- hdu 3341 Lost's revenge
- hdu 3341 Lost's revenge(AC自动机+DP)
- HDU 3341 Lost's revenge(AC自动机+DP)
- 【HDU】3341 Lost's revenge AC自动机+变进制+DP
- Hdu 3341 Lost's revenge (ac自动机+dp+hash)
- HDU - 3341 Lost's revenge(AC自动机+DP)
- [AC自动机+dp+变进制状压] hdu 3341 Lost's revenge
- hdu 3341 Lost's revenge(AC自动机+变进制状压DP)
- HDU 3341 Lost's revenge AC自动机 + 变进制状压DP
- hdu 3341 Lost's revenge (ac自动机+状压dp)
- hdu 3341Lost's revenge(ac自动机+dp)
- hdu 3341 Lost's revenge(dp+Ac自动机)
- HDU 3341 Lost's revenge (AC自动机 + DP)
- HDU 3341-Lost's revenge(AC自动机+DP+hash)
- Java 网络编程基础
- linux内核学习
- 取的设备的版本号
- Android 判断程序处于前台或者后台
- linux下socket编程实例
- HDU 3341 Lost's revenge
- 我的第一个svm程序:手写字识别
- DAO设计模式
- 单链表的基本操作
- HDU 3247 Resource Archiver
- C++中随机函数rand()和srand()的用法
- 第三章:UVa227 解题报告
- poj 杂题 - 1083 Moving Tables
- mixin