[USACO12JAN]Video Game Combos

AC自动机建立fail树后树上DP

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <string.h>
# include <algorithm>
# include <queue>
# define IL inline
# define RG register
# define ll long long
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;

IL ll Read(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
    return x * z;
}

const int MAXN(1010);
struct AC{
    int fail, ch[3], num;
} tree[MAXN];
int n, cnt, k, f[MAXN][MAXN], ans;
char t[MAXN];
queue <int> Q;

IL void Insert(){
    RG int len = strlen(t), x = 0;
    for(RG int i = 0; i < len; i++){
        if(!tree[x].ch[t[i] - 'A']) tree[x].ch[t[i] - 'A'] = ++cnt;
        x = tree[x].ch[t[i] - 'A'];
    }
    tree[x].num++;
}

IL void Bfs(){
    while(!Q.empty()) Q.pop();
       for(RG int i = 0; i < 3; i++)
           if(tree[0].ch[i]) Q.push(tree[0].ch[i]);
    while(!Q.empty()){
        RG int u = Q.front(); Q.pop();
        for(RG int i = 0; i < 3; i++)
            if(tree[u].ch[i]){
                tree[tree[u].ch[i]].fail = tree[tree[u].fail].ch[i];
                Q.push(tree[u].ch[i]);
            }
            else tree[u].ch[i] = tree[tree[u].fail].ch[i];
            tree[u].num += tree[tree[u].fail].num;
    }
}

int main(){
    n = Read(); k = Read();
    for(RG int i = 1; i <= n; i++){
        scanf(" %s", t);
        Insert();
    }
    Bfs();
    Fill(f, -127); f[0][0] = 0;
    for(RG int K = 1; K <= k; K++){
        for(RG int i = 0; i <= cnt; i++)
            for(RG int j = 0; j < 3; j++)
                f[K][tree[i].ch[j]]=max(f[K][tree[i].ch[j]],f[K - 1][i] + tree[tree[i].ch[j]].num);
    }
    for(RG int i = 0; i <= cnt; i++)
        ans = max(ans, f[k][i]);
    printf("%d\n", ans);
    return 0;
}

转载于:https://www.cnblogs.com/cjoieryl/p/8206389.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
只用一点点时间即可实现动作游戏的combo输入 Want to create an action game that allows you to perform combos? The GAC (Great Animation Combos) System is created just for that. Create 3D/2D games that take your animations and seamlessly provides cool combo sequences to your players. This asset comes packed with features to get your games up and running (and combo-ing) with a few clicks and minimal coding. Feature List: –NEW! 3rd Party Plugins Setup Menu– Add access to supported 3rd party Assets with just button clicks –NEW! Charged Activators-Hold down a specific activator input and release in time to provide a different animation attack –NEW! Debug Input Response Times-Allows the adjustment of input response times giving even more customized control. –3rd Party Activator Support– InControl, NEW! Control Freak, NEW! uGUI, and NEW! Rewired supported! (InControl, Control Freak and Rewired sold separately by their respective owners) –NEW 2D 3rd Party Support!– Tested to now support Smooth Moves asset right out of the box using Legacy Animations! –Context Variables– Use context variables to add conditions to Combos and Activators for limitless combo creations –Target Tracker Hit Detections– Use the tracker to have game objects react to hits with different animations and movements by calculating the distance and angle –Unity Physics Compatible– Use Unity’s physics system in conjunction with GAC with 3 different component modes –uScript and Playmaker Support– Use uScripts nodes and Playmaker states to call your activators! (uScript & Playmaker sold separately by their respective owners) –Mobile Support – Support for building to mobile devices using the Touch Gestures (PC/Mac, Android and iOS Supported) –Unity2D Compatible– Select a Movement Component Type to build in 3D or 2D officially supporting Unity Sprites that work with Mecanim –Sequence-Activators– Activate inputs in a sequence that trigger animations (eg. Down>Forward>P) for advanced combo creations –Sync-Activators– Combine inputs to trigger simultaneously (eg. A+S pressed together) for advanced combo creations –Multiplayer Support– Setup multiplayer gameplay by calling GAC on specific gameobjects –Delayed Animations– Create combos that link into animations when input event is delayed (eg. A, A…(wait)…A) –Mecanim Support– Add your animation states to use for combos. GAC plays well with states setup for other uses (Idle, Run etc) –Activator Setup Menu– Scripting basic events not required, do activator input setups through the inspector –Animation Linking – Combine your attack animations to create cool combos –Affect Specific Gameobject Layers – Customize what your animations can affect –Preview Animation Combo Setups with the intuitive GAC-PAC (Preview Animation Combos) Window –Full Source Code Access!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值