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. PowerMock学习(一)之PoweMock的入门--模拟新增学生操作

    关于powermock 在TDD领域Mock框架有很多,比如EasyMock,JMock,Mockito.可能有些同学会好奇了,为什么要重点把powermock拿出来呢,因为powermock可以解决 ...

  2. OC语言自学基础知识总结

    一.成员变量的作用域 二.点语法 三.构造方法 四.分类 五.类的本质 六.自动生成getter和setter方法 七.description方法 八.id类型 九.SEL 一.成员变量的作用域 @p ...

  3. HTML 转 PDF 之 wkhtmltopdf

    wkhtmltopdf是一个可以把html转为pdf的插件,有windows.linux等平台的版本,比较简单 官网下载 https://wkhtmltopdf.org/downloads.html  ...

  4. 【编程题与分析题】Javascript 之继承的多种实现方式和优缺点总结

    [!NOTE] 能熟练掌握每种继承方式的手写实现,并知道该继承实现方式的优缺点. 原型链继承 function Parent() { this.name = 'zhangsan'; this.chil ...

  5. 力扣(LeetCode)反转链表 个人题解

    反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶:你可以迭代或 ...

  6. Spring Boot2 系列教程(二十六)Spring Boot 整合 Redis

    在 Redis 出现之前,我们的缓存框架各种各样,有了 Redis ,缓存方案基本上都统一了,关于 Redis,松哥之前有一个系列教程,尚不了解 Redis 的小伙伴可以参考这个教程: Redis 教 ...

  7. 磁盘配额管理disk quotas

    条件: a.确保系统内核支持,Linux一般都支持 b.确保分区格式支持,ext2都只持! c.安装有quota软件,centos默认都有! (1)检查内核是否打开磁盘配额支持 [root@cento ...

  8. 移动端viewport模版

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta cont ...

  9. Clean Code 笔记 之 第四章 如何应用注释

    继上一篇笔记之后,今天我们讨论一下 代码中是存在注释是否是一件好的事情. 在我们开发的过程中讲究“名副其实,见名识意”,这也往往是很多公司的要求,但是有了这些要求是不是我们的代码中如果存在注释是不是意 ...

  10. Centos下安装PHP ldap扩展

    Centos下安装PHP ldap扩展,有两种方法,仅供参考. 一.在线安装 执行下面命令: 1 yum install PHP-ldap 可能出现的问题: Error: php70w-common- ...