【HDU 6017】 Girls Love 233 (DP)
Girls Love 233
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 720 Accepted Submission(s): 250Problem DescriptionBesides skipping class, it is also important to meet other girls for luras in the new term.As you see, luras sneaked into another girl's QQgroup to meet her indescribable aim.
However, luras can only speak like a cat. To hide her real identity, luras is very careful to each of her words.
She knows that many girls love saying "233",however she has already made her own word at first, so she needs to fix it.
Her words is a string of length n,and each character of the string is either '2' or '3'.
Luras has a very limited IQ which is only m.
She could swap two adjacent characters in each operation, which makes her losing 2 IQ.
Now the question is, how many substring "233"s can she make in the string while her IQ will not be lower than 0 after her operations?
for example, there is 1 "233" in "2333", there are 2 "233"s in "2332233", and there is no "233" in "232323".
InputThe first line is an integer T which indicates the case number.and as for each case,
the first line are two integers n and m,which are the length of the string and the IQ of luras correspondingly.
the second line is a string which is the words luras wants to say.
It is guaranteed that——
1 <= T <= 1000
for 99% cases, 1 <= n <= 10, 0 <= m <= 20
for 100% cases, 1 <= n <= 100, 0<= m <= 100
OutputAs for each case, you need to output a single line.there should be one integer in the line which represents the largest possible number of "233" of the string after her swap.
Sample Input3
6 2
233323
6 1
233323
7 4
2223333Sample Output2
1
2Source
【分析】
考虑交换完之后的序列的样子:
假设是2333233->2333332
只考虑2的移动就好了,肯定是第一个2对应末状态第一个2,以此类推。。。
所以DP考虑2填在什么位置就好了。
f[i][j][k][p]表示填了i个数,有j个2,花费了k,p是最后几个数的状态。
0表示没有,1表示有‘2’,2表示有’23‘。
然后直接状态转移就好了【T那么大理论上不是过不了的吗??
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0xfffffff int mymax(int x,int y) {return x>y?x:y;} int f[][][][];
int pos[];
char s[]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,sm=;
scanf("%d%d",&n,&m);
scanf("%s",s+);
for(int i=;i<=n;i++) if(s[i]=='') pos[++sm]=i;
// memset(f,0,sizeof(f));
for(int i=;i<=n;i++) for(int j=;j<=n;j++) for(int k=;k<=m;k++) f[i][j][k][]=f[i][j][k][]=f[i][j][k][]=-INF;
f[][][][]=;
int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=sm;j++)
for(int k=;k<=m;k++)
{
int ad=*abs(i-pos[j+]);
f[i][j+][k+ad][]=mymax(f[i][j+][k+ad][],f[i-][j][k][]);
f[i][j+][k+ad][]=mymax(f[i][j+][k+ad][],f[i-][j][k][]);
f[i][j+][k+ad][]=mymax(f[i][j+][k+ad][],f[i-][j][k][]); f[i][j][k][]=mymax(f[i][j][k][],f[i-][j][k][]);
f[i][j][k][]=mymax(f[i][j][k][],f[i-][j][k][]);
f[i][j][k][]=mymax(f[i][j][k][],f[i-][j][k][]+);
if(j==sm)
{
ans=mymax(ans,f[i][j][k][]);
ans=mymax(ans,f[i][j][k][]);
ans=mymax(ans,f[i][j][k][]);
}
}
printf("%d\n",ans);
}
return ;
}
2017-04-19 10:38:30
【HDU 6017】 Girls Love 233 (DP)的更多相关文章
- 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)
题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...
- 【BZOJ 1084】 [SCOI2005]最大子矩阵(DP)
题链 http://www.lydsy.com/JudgeOnline/problem.php?id=1084 Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩 ...
- 【RQNOJ PID106】最大加权矩形(DP)
题目描述 给定一个正整数n( n<=100),然后输入一个N*N矩阵.求矩阵中最大加权矩形,即矩阵的每一个元素都有一权值,权值定义在整数集上.从中找一矩形,矩形大小无限制,是其中包含的所有元素的 ...
- 【HDU - 4342】History repeat itself(数学)
BUPT2017 wintertraining(15) #8C 题意 求第n(n<2^32)个非完全平方数m,以及\(\sum_{i=1}^m{\lfloor\sqrt i\rfloor}\) ...
- 【HDU 2874】Connections between cities(LCA)
dfs找出所有节点所在树及到树根的距离及深度及父亲. i和j在一棵树上,则最短路为dis[i]+dis[j]-dis[LCA(i,j)]*2. #include <cstring> #in ...
- 【HDU - 1257】最少拦截系统(贪心)
最少拦截系统 Descriptions: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的 ...
- 【HDU 5402】Travelling Salesman Problem(构造)
被某题卡SB了,结果这题也没读好...以为每一个格子能够有负数就当搜索做了.怎么想也搜只是去,后来发现每一个格子是非负数,那么肯定就是构造题. 题解例如以下: 首先假设nn为奇数或者mm为奇数,那么显 ...
- 【洛谷】P2725 邮票 Stamps(dp)
题目背景 给一组 N 枚邮票的面值集合(如,{1 分,3 分})和一个上限 K —— 表示信封上能够贴 K 张邮票.计算从 1 到 M 的最大连续可贴出的邮资. 题目描述 例如,假设有 1 分和 3 ...
- [BZOJ2287]【POJ Challenge】消失之物(DP)
传送门 f[i][j]表示前i个物品,容量为j的方案数c[i][j]表示不选第i个物品,容量为j的方案数两个数组都可以压缩到一维 那么f[i][j] = f[i - 1][j] + f[i - 1][ ...
随机推荐
- 【BZOJ】1597 [Usaco2008 Mar]土地购买
[算法]DP+斜率优化 [题意]n(n≤50000)块土地,长ai宽bi,可分组购买,每组代价为max(ai)*max(bi),求最小代价. [题解] 斜率优化:http://www.cnblogs. ...
- wampserver 虚拟主机
转载:http://blog.csdn.net/knight_quan/article/details/51830683 1.背景: 在进行网站开发的时候,通常需要以http://localhost或 ...
- 论文里有公式?用texlive+texstudio(windows下)
要写论文了,但论文里有一大堆公式,感觉很麻烦,经过询问同学知道有tex这么个东西,可以像写代码一样写论文,许多论文的格式都有相关的模板,所以学习一下,这里记录一下环境安装. texlive和texst ...
- HBA 介绍
1.首先介绍一下什么是HBA. 这里所说的HBA,全称FC HBA,也就是Fibre Channel Host Bus Adapter.在FC网络中,主机(如服务器)需要和FC网络.FC存储设备(如S ...
- CSS 中 nth-child 和 nth-of-type 的区别
假设有如下代码结构,想要查找 Piggy 那个 p <section> <h1>Words</h1> <p>Little</p> <p ...
- keypress 、keydown、keyup后触发回车
1.keypress .keydown.keyup的区别 keypress表示键盘按下的全过程,只有按下任意字母数字键(后退.删除等系统功能键无效)时才触发,捕获到的keyCode区分大小写 keyd ...
- 设计模式之笔记--解释器模式(Interpreter)
解释器模式(Interpreter) 定义 解释器模式(Interpreter),给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子. 类图 描述 Expr ...
- JavaScript变量命名规则:匈牙利命名法
匈牙利命名法语法 变量名=类型+对象描述 类型指变量的类型 对象描述指对象名字全称或名字的一部分,要求有明确含义,命名要容易记忆容易理解. 提示 虽然JavaScript变量表面上没有类型,但是Jav ...
- Spring mvc知识点总结——面试篇
一.MVC思想MVC(Model-View-Controller)三元组的概念:1.Model(模型):数据模型,提供要展示的数据,因此包含数据和行为,可以认为是领域模型或JavaBean组件(包含数 ...
- LeetCode312. Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...