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. python 快速发送大量邮件

    因为公司需求,需要发送千万封级别邮件. # coding:utf-8 import csv import smtplib from email.mime.text import MIMEText im ...

  2. jsoup爬虫实战心得

    1.heder很重要,一切尽在header中.尤其cookie,useragent. 2.对于加密的连接,查看js加密过程并试着通过java或你正在使用的语言去实现 3.查看在跳转之前前端发起的关键请 ...

  3. Comet OJ - 2019国庆欢乐赛 C题 两排房子

    ###题目链接### 题目大意:这里有横着的两排房子,给你每个房子的左端点和右端点.若两排房子中分别有两个房子 x y ,他们在横坐标上有重叠部分(端点重叠也算),则被称为 “对门” 关系. 问你总共 ...

  4. [LC]206题 Reverse Linked List (反转链表)(链表)

    ①英文题目 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5-> ...

  5. 分组取topN

    假设有这样一个文件,文件内容如下 class1 class2 class1 class1 class2 class2 class1 class2 class1 class2 要求按照班级分组取出每个班 ...

  6. nyoj 16-矩形嵌套(贪心 + 动态规划DP)

    16-矩形嵌套 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:13 submit:28 题目描述: 有n个矩形,每个矩形可以用a,b来描述,表示长和 ...

  7. Ubuntu 16.04 安装Maven3.3.9

    1 下载地址 http://maven.apache.org/download.cgi 2 将下载到的apache-maven-3.3.9-bin.tar.gz文件上传到/temp目录下,然后切换到r ...

  8. day 41 css固定位置 以及小米商城项目

    .如何让一个绝对定位的盒子居中 left:%; margin-left:- 宽度的一半 .固定定位 position: fixed; ()脱标 参考点:浏览器的左上角 作用:固定导航栏 返回顶部 小广 ...

  9. Pycharm报错连接linux服务器报错:Could not verify `ssh-rsa` host key with fingerprint

    忘记了截图,后来解决了就懒得再去重新制造错误了.大概记得是通过ssh连接linux时,报错 Could not verify `ssh-rsa` host key with fingerprint . ...

  10. tensorflow的函数

    1. if __name__=="__main__": tf.app.run()#运行之前定义的main函数#将传进来的参数,以及flags.FLAGS定义的参数传入到main函数 ...