Invoker

Time Limit: 15000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 117    Accepted Submission(s): 35

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(R). 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.

 
Source
 

参考代码:
#include<bits/stdc++.h>
using namespace std;
const int size=1e5+;
const int inf=0x3f3f3f3f;
char ss[size];
int dp[size][][];
int ans[size];
char s[][]={"QQQ","QQW","QQE","WWW","QWW","WWE","EEE","QEE","WEE","QWE"};
int stru[][]={{,,},{,,},{,,},{,,},{,,},{,,}};
inline int id(char c)
{
if(c=='Q') return ;
if(c=='W') return ;
if(c=='E') return ;
}
int ty[size];
inline int swap(char c)
{
if(c=='Y') return ;
if(c=='V') return ;
if(c=='G') return ;
if(c=='C') return ;
if(c=='X') return ;
if(c=='Z') return ;
if(c=='T') return ;
if(c=='F') return ;
if(c=='D') return ;
if(c=='B') return ;
}
int main()
{
while(~scanf("%s",ss+))
{
int len=strlen(ss+);
for(int i=;i<=len;i++)
{
for(int j=;j<=;j++)
{
for(int k=;k<=;k++)
{
dp[i][j][k]=inf;
}
}
}
for(int i=;i<=len;i++)
{
ty[i]=swap(ss[i]);
ans[i]=inf;
}
ans[]=;
dp[][id(s[ty[]][])][id(s[ty[]][])]=;
dp[][id(s[ty[]][])][id(s[ty[]][])]=;
dp[][id(s[ty[]][])][id(s[ty[]][])]=;
dp[][id(s[ty[]][])][id(s[ty[]][])]=;
dp[][id(s[ty[]][])][id(s[ty[]][])]=;
dp[][id(s[ty[]][])][id(s[ty[]][])]=;
for(int i=;i<=len;i++)
{
if(ty[i]==ty[i-])
{
for(int j=;j<=;j++)
{
for(int k=;k<=;k++)
{
dp[i][j][k]=dp[i-][j][k];
}
}
ans[i]=ans[i-];
continue;
}
dp[i][id(s[ty[i]][])][id(s[ty[i]][])]=+ans[i-];
dp[i][id(s[ty[i]][])][id(s[ty[i]][])]=+ans[i-];
dp[i][id(s[ty[i]][])][id(s[ty[i]][])]=+ans[i-];
dp[i][id(s[ty[i]][])][id(s[ty[i]][])]=+ans[i-];
dp[i][id(s[ty[i]][])][id(s[ty[i]][])]=+ans[i-];
dp[i][id(s[ty[i]][])][id(s[ty[i]][])]=+ans[i-];
for(int j=;j<;j++)
{
dp[i][id(s[ty[i]][stru[j][]])][id(s[ty[i]][stru[j][]])]=min(dp[i][id(s[ty[i]][stru[j][]])][id(s[ty[i]][stru[j][]])],dp[i-][id(s[ty[i]][stru[j][]])][id(s[ty[i]][stru[j][]])]+);
for(int k=;k<=;k++)
dp[i][id(s[ty[i]][stru[j][]])][id(s[ty[i]][stru[j][]])]=min(dp[i][id(s[ty[i]][stru[j][]])][id(s[ty[i]][stru[j][]])],dp[i-][k][id(s[ty[i]][stru[j][]])]+);
ans[i]=min(ans[i],dp[i][id(s[ty[i]][stru[j][]])][id(s[ty[i]][stru[j][]])]);
}
}
printf("%d\n",ans[len]+len);
}
return ;
}

2019CCPC秦皇岛I题 Invoker(DP)的更多相关文章

  1. 2019ccpc秦皇岛/Gym102361 I - Invoker dp

    题意: 连续3个特定的按键(在这3个中不要求顺序)能使出某个技能,使出不同技能所需要的按键可以重叠,给你一个技能序列,问你最少花费多少次按键能按顺序使出这些招数. 题解: dp,dp[i][j]代表使 ...

  2. HDU6739 2019CCPC秦皇岛赛区 I. Invoker

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6739思路:暴力dp           一个special skill最多有6种排列组合          ...

  3. 2019CCPC秦皇岛 E题 Escape(网络流)

    Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  4. 2019CCPC秦皇岛D题 Decimal

    Decimal Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  5. hdoj1028;他们说这题叫dp...

    #include<cstdio> #include<string> #include<iostream> #include<vector> #inclu ...

  6. 2019-ccpc秦皇岛现场赛

    https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...

  7. 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)

    1952: [Sdoi2010]城市规划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 23[Submit][Status][ ...

  8. HDU5697 刷题计划 dp+最小乘积生成树

    分析:就是不断递归寻找靠近边界的最优解 学习博客(必须先看这个): 1:http://www.cnblogs.com/autsky-jadek/p/3959446.html 2:http://blog ...

  9. NYOJ201-作业题-(dp)

    201-作业题 内存限制:64MB 时间限制:3000ms 特判: No通过数:9 提交数:28 难度:3 题目描述: 小白同学这学期有一门课程叫做<数值计算方法>,这是一门有效使用数字计 ...

随机推荐

  1. html5自动横屏的方法

    html5自动横屏的方法<pre>var evt = "onorientationchange" in window ? "orientationchange ...

  2. Java-100天知识进阶-基本类型-知识铺(一)

    知识铺: 致力于打造轻知识点,持续更新每次的知识点较少,阅读不累.不占太多时间,不停地来唤醒你记忆深处的知识点. Java的两大数据类型: 一.内置数据类型 二.引用数据类型 内置数据类型 Java语 ...

  3. C++中对C的扩展学习新增语法——lambda 表达式(匿名函数)

    1.匿名函数基础语法.调用.保存 1.auto lambda类型 2.函数指针来保存注意点:[]只能为空,不能写东西 3.std::function来保存 2.匿名函数捕捉外部变量(值方式.引用方式) ...

  4. CSS复合选择器是什么?复合选择器是如何工作

    复合选择器介绍 复合选择器其实很好理解,说白了就跟我们生活中的有血缘关系家庭成员一样,通过标签或者class属性或id属性,去找对应的有血缘关系的某个选择器,具体的大家往下看哦. 如果是初学者对基本的 ...

  5. hdu 1556 Color the ball (树状数组)

    Color the ballTime Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. react路由的动态传参

    ① 定义规则 ②传值 ③获取传过来的值

  7. 笔记本进入BIOS设置

    转眼间,到大三了. 在学习<Red Hat Linux 服务器搭建与管理>这门课时,刚开学第一节,就是虚拟机,但是最烦恼的是我们笔记本电脑的默认设置,它把虚拟化给禁止了. 1,首先,我们需 ...

  8. PHP中接口与抽象类的异同点有哪些

    接口与抽象类的相同点: 1.抽象类和接口都有抽象方法 2.抽象类和接口不能创建实例对象 3.抽象类和接口使用意义相同(定义一种规范) 接口与抽象类的不同点: 1.接口中的方法必须全要是抽象方法(不能用 ...

  9. 2019-10-24:渗透测试,sqli-labe,less18,19关

    less19基于错误_POST_Referer_请求头注入 查看关键源码,跟18关不一样的只是,回显的是Referer不是User-Agent,判断INSERT语句结构:INSERT INTO tab ...

  10. webpackd学习的意义

    高速发展的前端技术,与浏览器支持的不相匹配.导致前端必须把前端比较先进的技术进行一层编码从而使得浏览器可以加载. 比如前端框架Vue,Angular,React.Less,Sass.TypeScrip ...