HDU3341 Lost's revenge

Lost's revenge

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2816    Accepted Submission(s): 716



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.
 

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.
 

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
  
3 AC CG GT CGAT 1 AA AAA 0
 

Sample Output
  
Case 1: 3 Case 2: 2
 

Author
Qinz@XDU
 

Source
 
题意:给出几个数论基因,要求将一个字符串重新排列使这几个数论基因最多(可以重叠),输出数论基因出现最多的次数。
分析:AC自动机+状态压缩DP,必须要进行状态压缩,不然就要开一个5维数组,表示A,C,G,T的个数和走到树上一节点的最大个数,压缩之后dp[i][j],i就表示一个状态,j表示走到了哪个节点。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXM=15000;
const int MAXN=510;
int size;
int dp[MAXM][MAXN],K[5];
char s[MAXN];
bool vis[MAXM];
struct node
{
    int fail;
    int next[4];
    int cnt;
    void init()
    {
        fail=cnt=0;
        memset(next,0,sizeof(next));
    }
}tree[MAXN];
int get(char c)
{
    if(c=='A')
        return 0;
    if(c=='C')
        return 1;
    if(c=='G')
        return 2;
    return 3;
}
void insert(char *str)
{
    int i=0,p=0,index;
    while(str[i])
    {
        index=get(str[i]);
        if(tree[p].next[index]==0)
        {
            tree[++size].init();
            tree[p].next[index]=size;
        }
        p=tree[p].next[index];
        i++;
    }
    tree[p].cnt++;
}
void build_ac_automation()
{
    int i;
    queue<int> q;
    q.push(0);
    while(!q.empty())
    {
        int temp=q.front();
        q.pop();
        for(i=0;i<4;i++)
        {
            if(tree[temp].next[i])
            {
                int p=tree[temp].next[i];
                if(temp)
                {
                    tree[p].fail=tree[tree[temp].fail].next[i];
                    tree[p].cnt+=tree[tree[p].fail].cnt;
                }
                q.push(p);
            }
            else
                tree[temp].next[i]=tree[tree[temp].fail].next[i];
        }
    }
}
int flag=1;
void solve()
{
    queue<int> q;
    int head,temp;
    int i,j,k,ans,cnt[4];
    memset(dp,-1,sizeof(dp));
    memset(cnt,0,sizeof(cnt));
    memset(vis,0,sizeof(vis));
    for(i=0;s[i];i++)
    {
        cnt[get(s[i])]++;
    }
    for(i=0;i<5;i++)
    {
        if(i)
            K[i]=K[i-1]*(cnt[i-1]+1);
        else
            K[i]=1;
    }
    ans=dp[0][0]=0;
    q.push(0);
    vis[0]=1;
    while(!q.empty())
    {
        head=q.front();
        q.pop();
        for(i=0;i<=size;i++)
        {
            if(dp[head][i]<0)
                continue;
            for(j=0;j<4;j++)
            {
                k=head%K[j+1]/K[j];
                if(k>=cnt[j])
                    continue;
                temp=head+K[j]; //j(对应一个碱基)的状态
                k=tree[i].next[j];  //从i节点到j节点
                if(dp[temp][k]<dp[head][i]+tree[k].cnt)
                {
                    dp[temp][k]=dp[head][i]+tree[k].cnt;
                    ans=max(ans,dp[temp][k]);
                    if(!vis[temp])
                    {
                        vis[temp]=1;
                        q.push(temp);
                    }
                }
            }
        }
    }
    printf("Case %d: %d\n",flag++,ans);
}
int main()
{
    int n,i;
    while(scanf("%d",&n)==1&&n)
    {
        size=0;
        tree[0].init();
        for(i=0;i<n;i++)
        {
            scanf("%s",s);
            insert(s);
        }
        scanf("%s",s);
        build_ac_automation();
        solve();
    }
    return 0;
}


【SCI一区复现】基于配电网韧性提升的应急移动电源预配置和动态调度(下)—MPS动态调度(Matlab代码实现)内容概要:本文档围绕“基于配电网韧性提升的应急移动电源预配置和动态调度”主题,重点介绍MPS(Mobile Power Sources)动态调度的Matlab代码实现,是SCI一区论文复现的技术资料。内容涵盖在灾害或故障等极端场景下,如何通过优化算法对应急移动电源进行科学调度,以提升配电网在突发事件中的恢复能力与供电可靠性。文档强调采用先进的智能优化算法进行建模求解,并结合IEEE标准测试系统(如IEEE33节点)进行仿真验证,具有较强的学术前沿性和工程应用价值。; 适合人群:具备电力系统基础知识和Matlab编程能力,从事电力系统优化、配电网韧性、应急电源调度等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于复现高水平期刊(SCI一区、IEEE顶刊)中关于配电网韧性与移动电源调度的研究成果;②支撑科研项目中的模型构建与算法开发,提升配电网在故障后的快速恢复能力;③为电力系统应急调度策略提供仿真工具与技术参考。; 阅读建议:建议结合前篇“MPS预配置”内容系统学习,重点关注动态调度模型的数学建模、目标函数设计与Matlab代码实现细节,建议配合YALMIP等优化工具包进行仿真实验,并参考文中提供的网盘资源获取完整代码与数据。
一款AI短视频生成工具,只需输入一句产品卖点或内容主题,软件便能自动生成脚本、配音、字幕和特效,并在30秒内渲染出成片。 支持批量自动剪辑,能够实现无人值守的循环生产。 一键生成产品营销与泛内容短视频,AI批量自动剪辑,高颜值跨平台桌面端工具。 AI视频生成工具是一个桌面端应用,旨在通过AI技术简化短视频的制作流程。用户可以通过简单的提示词文本+视频分镜素材,快速且自动的剪辑出高质量的产品营销和泛内容短视频。该项目集成了AI驱动的文案生成、语音合成、视频剪辑、字幕特效等功能,旨在为用户提供开箱即用的短视频制作体验。 核心功能 AI驱动:集成了最新的AI技术,提升视频制作效率和质量 文案生成:基于提示词生成高质量的短视频文案 自动剪辑:支持多种视频格式,自动化批量处理视频剪辑任务 语音合成:将生成的文案转换为自然流畅的语音 字幕特效:自动添加字幕和特效,提升视频质量 批量处理:支持批量任务,按预设自动持续合成视频 多语言支持:支持中文、英文等多种语言,满足不同用户需求 开箱即用:无需复杂配置,用户可以快速上手 持续更新:定期发布新版本,修复bug并添加新功能 安全可靠:完全本地本地化运行,确保用户数据安全 用户友好:简洁直观的用户界面,易于操作 多平台支持:支持Windows、macOS和Linux等多个操作系统
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值