2019CCPC秦皇岛I题 Invoker(DP)
Invoker
Time Limit: 15000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 117 Accepted Submission(s): 35
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.
One possible scheme is QWWREERERWQRQRR.
参考代码:
#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)的更多相关文章
- 2019ccpc秦皇岛/Gym102361 I - Invoker dp
题意: 连续3个特定的按键(在这3个中不要求顺序)能使出某个技能,使出不同技能所需要的按键可以重叠,给你一个技能序列,问你最少花费多少次按键能按顺序使出这些招数. 题解: dp,dp[i][j]代表使 ...
- HDU6739 2019CCPC秦皇岛赛区 I. Invoker
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6739思路:暴力dp 一个special skill最多有6种排列组合 ...
- 2019CCPC秦皇岛 E题 Escape(网络流)
Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- 2019CCPC秦皇岛D题 Decimal
Decimal Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- hdoj1028;他们说这题叫dp...
#include<cstdio> #include<string> #include<iostream> #include<vector> #inclu ...
- 2019-ccpc秦皇岛现场赛
https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...
- 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)
1952: [Sdoi2010]城市规划 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 73 Solved: 23[Submit][Status][ ...
- HDU5697 刷题计划 dp+最小乘积生成树
分析:就是不断递归寻找靠近边界的最优解 学习博客(必须先看这个): 1:http://www.cnblogs.com/autsky-jadek/p/3959446.html 2:http://blog ...
- NYOJ201-作业题-(dp)
201-作业题 内存限制:64MB 时间限制:3000ms 特判: No通过数:9 提交数:28 难度:3 题目描述: 小白同学这学期有一门课程叫做<数值计算方法>,这是一门有效使用数字计 ...
随机推荐
- kubernetes 控制器详解【持续完善中】
目录 资源创建详解 一:Pod及常用参数 1.简介 2.模板 3.删除pod 4.设置Pod主机名 5.镜像拉取策略(ImagePullPolicy) 二:RC 1.简介 2.模板 三:Deploym ...
- 比较一下inner join(可直接简写为join)和where直接关联
SELECT * FROM A ,B WHERE A.ID = B.ID 是比较常用的2个表关联.之前一直用这个,后来换了家公司发现这家公司的报表大多数都是用inner join,稍微研究了一下.查阅 ...
- js的split()和join()的用法
split() 方法用于把一个字符串分割成字符串数组.split[splɪt]:vt. 分离:使分离:劈开:离开:分解 stringObject.split(separator,howmany) se ...
- nyoj 1364-治安管理 (INT_MAX)
1364-治安管理 内存限制:128MB 时间限制:3000ms 特判: No 通过数:6 提交数:6 难度:2 题目描述: SZ市是中国改革开放建立的经济特区,是中国改革开放的窗口,已发展为有一定影 ...
- Win32 COM组件 x Android Service (二)
继续上一篇. 如果不使用AIDL(Android Interface Definition Language接口描述语言)编写服务接口的话,(COM组件,CORBA组件,ICE组件以及其它远程调用框架 ...
- PostGIS 安装教程(Linux)(二)
##接上篇,上篇讲述了Postgresql的安装,此篇介绍postgis的安装 ##附上上篇链接:https://www.cnblogs.com/giser-s/p/11195419.html 二.安 ...
- vue学习笔记(八)组件校验&通信
前言 在上一章博客的内容中vue学习笔记(七)组件我们初步的认识了组件,并学会了如何定义局部组件和全局组件,上一篇内容仅仅只是对组件一个简单的入门,并没有深入的了解组件当中的其它机制,本篇博客将会带大 ...
- 题解——面积(area.cpp)
题目来源&题面简述: 思路与算法选择: 只有*里面的部分对我们有用,所以可以将 *号外的部分标记一下. 可以用著名的BFS大法实现此过程.(连通块) 连通块模板: #include<bi ...
- 从面试官甄别项目经验的角度,说说如何在简历中写项目经验(java后端方向)
在大多的JD(职位介绍)里,会写明该职位需要xx时间的相关经验,换句话说就是需要在简历中看到一定年限的相关商业项目经验,否则估计连面试的机会都没. 在本文里,不讨论这种门槛是否合理,而会以Java相关 ...
- Python3学习-基础
1.直接运行.py文件 在Windows上是不行的,但是在Mac和Linux上是可以的,方法是在.py文件的第一行加上一个特殊的注释: #!/usr/bin/env python3 print('he ...