【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】4873: [Shoi2017]寿司餐厅
[题目]#2146. 「SHOI2017」寿司餐厅 [题意]给定n种寿司的代号,取区间[i,j]的寿司收益是d[i,j]和所有子区间的d,吃了c(c>0)种代号x的寿司的代价是mx^2+cx,给 ...
- cocos2dx学习,转摘一些链接
cocos2d-x学习笔记09:动作2:持续动作 ccBezierConfig 贝塞尔坐标点是相对的 Box2DTestBed很有意思的demo,可惜自己水平有限针对其实现还是没弄明白,以后有时间多学 ...
- 【洛谷P2515【HAOI2010】】软件安装
题目描述 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和最大). 但是 ...
- password passphrase passcode 的区别
In general, passphrases are long passwords and passcodes are numeric-only passwords.
- Apache+jboss群集部署
Jboss default方式上的Cluster配置[二] - 操作系统http://www.myexception.cn/operating-system/862858.html Jboss def ...
- 148.Sort List---链表排序(冒泡、归并)
题目链接 题目大意:对链表进行排序,要求时间复杂度是o(nlgn). 法一:冒泡,不交换结点,而交换结点中的数值.超时了.代码如下: public ListNode sortList(ListNode ...
- Oracle安装出现报错
报错信息如下: >>> Couldnot execute auto check for display colors using command /usr/bin/xdpyinfo. ...
- EnumSet基本用法
enum Season { SPRING, SUMMER, FALL, WINTER } public class EnumSetTest { public static void main(Stri ...
- (二) Mysql 数据类型简介
第一节:整数类型.浮点数类型和定点数类型 1,整数类型 2,浮点数类型和定点数类型 M 表示:数据的总长度(不包括小数点): D 表示:小数位: 例如 decimal(5,2) 123.45 ...
- HTTP协议头注射漏洞实例
HTTP 响应头文件中包含未经验证的数据会引发 cache-poisoning.cross-site scripting.cross-user defacement.page hijacking.co ...