ccpc 秦皇岛 Invoker (暴力dp)

Problem Description
In dota2, there is a hero named Invoker. He has 3 basic skills in the game, which are Quas, Wex and Exort. Once he launches a basic skill, he will gain the corresponding element, where Quas gives “Q”, Wex gives “W” and Exort gives “E”.
Invoker can’t have more than 3 elements simultaneously. If he launches a basic skill when he already owns 3 elements, he will get the corresponding element and lose the element he gained the earliest.
As can be seen, there are 10 unordered combinations of 3 elements in 3 types, each represents a special skill, which are as follows:

Cold Snap: unordered element combination “QQQ”, denoted by “Y”

Ghost Walk: unordered element combination “QQW”, denoted by “V”

Ice Wall: unordered element combination “QQE”, denoted by “G”

EMP: unordered element combination “WWW”, denoted by “C”

Tornado: unordered element combination “QWW”, denoted by “X”

Alacrity: unordered element combination “WWE”, denoted by “Z”

Sun Strike: unordered element combination “EEE”, denoted by “T”

Forge Spirit: unordered element combination “QEE”, denoted by “F”

Chaos Meteor: unordered element combination “WEE”, denoted by “D”
Deafening Blast: unordered element combination “QWE”, denoted by “B”
When Invoker owns 3 elements, he can launch the invoking skill, denoted by “R”, to gain the special skill according to the elements he currently owns. After invoking, the elements won’t disappear, and the chronological order of the 3 elements won’t change.
Now given a sequence of special skills, you want to invoke them one by one with using the minimum number of basic skills(Q,W,E) and invoking skill®. Print the minimum number in a single line.
At the beginning, Invoker owns no elements. And you should re-invoke the special skills even if you have already invoked the same skills just now.

Input
Input a single line containing a string s (1 ≤ |s| ≤ 100 000) that only contains uppercase letters in {B, C, D, F, G, T, V, X, Y, Z}, denoting the sequence of special skills.

Output
Output a single line containing a positive integer, denoting the minimum number of skills to launch.

Sample Input
XDTBVV

Sample Output
15
Hint
One possible scheme is QWWREERERWQRQRR.

题意
有10种技能,每种技能由三个无序字符串释放,释放技能为R,求最短字符串。

思路
直接暴力枚举
dp方程为dp[i][j]=min(dp[i][j],dp[i-1][k]+cal);
我个人认为难点在于模拟的过程==
我脑抽模拟错了return 3的情况,狂wa了10次,最后是随机数搞了一个长度为10的样例发现的。

代码

#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 998244353;
using namespace std;
namespace fastIO {
    inline void input(int& res) {
        char c = getchar();res = 0;int f = 1;
        while (!isdigit(c)) { f ^= c == '-'; c = getchar(); }
        while (isdigit(c)) { res = (res << 3) + (res << 1) + (c ^ 48);c = getchar(); }
        res = f ? res : -res;
    }
    inline ll qpow(ll a, ll b) {
        ll ans = 1, base = a;
        while (b) {
            if (b & 1) ans = (ans * base % mod +mod )%mod;
            base = (base * base % mod + mod)%mod;
            b >>= 1;
        }
        return ans;
    }
}
using namespace fastIO;
const int N = 1e5+5;
int Case,n;
const int INF = 0x3f3f3f3f; 
string s;
string ans[15][6]=
{
    {"QQQ","QQQ","QQQ","QQQ","QQQ","QQQ"},
    {"QQW","QQW","QWQ","QWQ","WQQ","WQQ"},
    {"QQE","QQE","QEQ","QEQ","EQQ","EQQ"},
    {"WWW","WWW","WWW","WWW","WWW","WWW"},
    {"QWW","QWW","WQW","WQW","WWQ","WWQ"},
    {"EWW","EWW","WEW","WEW","WWE","WWE"},
    {"EEE","EEE","EEE","EEE","EEE","EEE"},
    {"QEE","QEE","EQE","EQE","EEQ","EEQ"},
    {"WEE","WEE","EWE","EWE","EEW","EEW"},
    {"QWE","QEW","WQE","WEQ","EQW","EWQ"},
};
int dp[N][7];
map<char,int> zr;
int cal(int start,int end,int vs,int ve){
    string ss = ans[zr[s[start]]][vs];
    string ee = ans[zr[s[end]]][ve];
    if(ss==ee) return 0;
    if(ss[2]==ee[1]&&ss[1]==ee[0]) return 1;
    if(ss[2]==ee[0]) return 2;
    return 3;
}
int main(){
    //freopen("out.txt","w+",stdout);
    zr['Y']=0,zr['V']=1,zr['G']=2,zr['C']=3,zr['X']=4,zr['Z']=5,zr['T']=6,zr['F']=7,zr['D']=8,zr['B']=9;
    Case=1;
    //input(Case);
    while(Case--){
        while(cin>>s){
            memset(dp,INF,sizeof(dp));
            for(int i=0;i<6;i++) dp[0][i]=3;
            int len=s.size();
            for(int i=1;i<len;i++){
                for(int j=0;j<6;j++){
                    for(int k=0;k<6;k++){
                        dp[i][j]=min(dp[i][j],dp[i-1][k]+cal(i-1,i,k,j)); 
                    }
                }
            }
            int minn=INF;
            for(int i=0;i<6;i++)
                minn=min(minn,dp[len-1][i]);
            printf("%d\n",minn+len);    
    
        }
    }
    return 0;
}
/*VFXYBXDDGX*/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值