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. C++中对封装的语法支持——重载运算符

    重载运算符 1.对于自定义类型,编译器不知道运算规则,而重载运算符会将两个对象相加转换为函数调用. 2.运算符重载转换的函数调用,函数名字是固定的规则. (1) 如果重载+号运算符,函数名字就是:op ...

  2. 斐波那契数列的实现(C语言)

    int fibonacci(int positon){ if(position==1||position==2){ return 1; } return fibonacci(position-1)+f ...

  3. netty源码解析(4.0)-29 Future模式的实现

    Future模式是一个重要的异步并发模式,在JDK有实现.但JDK实现的Future模式功能比较简单,使用起来比较复杂.Netty在JDK Future基础上,加强了Future的能力,具体体现在: ...

  4. 关于html与css的标签及属性(text文本属性、背景background属性、表格标签table、列表、)

    text文本属性1.颜色 colorcolor:red: 2.文本缩进text-indant属性值 num+px text-indant:10px:3.文本修饰 text-decoration属性值: ...

  5. nyoj 349 (poj 1094) (拓扑排序)

    Sorting It All Out 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 An ascending sorted sequence of distinct ...

  6. C语言|博客作业05

    这个作业属于哪个课程 C语言程序设计II 这个作业的要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-1/homework/9825 我在这个课程的 ...

  7. 用图解&&实例讲解php是如何实现websocket实时消息推送的

    WebSocket是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. 以前的推送技术使用 Ajax 轮询,浏览器需要不断地向服务器发送http请求来获取最新的数据,浪费很多的带 ...

  8. python主线程与子线程的结束顺序

    引用自 主线程退出对子线程的影响--YuanLi 的一段话: 对于程序来说,如果主进程在子进程还未结束时就已经退出,那么Linux内核会将子进程的父进程ID改为1(也就是init进程),当子进程结束后 ...

  9. Linux安装redis数据库

    这几天在搞redis数据库,花了好大功夫,才成功安装在Linux上,这里将自己的安装步骤分享出来,同时也做个记录,备忘. 新人一枚,不对之处,请多指教! 首先登陆Linux服务器 Linux里,我习惯 ...

  10. SpringBoot:带你认认真真梳理一遍自动装配原理

    前言 Spring翻译为中文是“春天”,的确,在某段时间内,它给Java开发人员带来过春天,但是随着我们项目规模的扩大,Spring需要配置的地方就越来越多,夸张点说,“配置两小时,Coding五分钟 ...