Girls Love 233

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 720    Accepted Submission(s): 250

Problem Description
Besides 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".

Input
The 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

Output
As 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 Input
3
6 2
233323
6 1
233323
7 4
2223333
Sample Output
2
1
2
Source

【分析】

  考虑交换完之后的序列的样子:

  假设是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)的更多相关文章

  1. 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)

    题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...

  2. 【BZOJ 1084】 [SCOI2005]最大子矩阵(DP)

    题链 http://www.lydsy.com/JudgeOnline/problem.php?id=1084 Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩 ...

  3. 【RQNOJ PID106】最大加权矩形(DP)

    题目描述 给定一个正整数n( n<=100),然后输入一个N*N矩阵.求矩阵中最大加权矩形,即矩阵的每一个元素都有一权值,权值定义在整数集上.从中找一矩形,矩形大小无限制,是其中包含的所有元素的 ...

  4. 【HDU - 4342】History repeat itself(数学)

    BUPT2017 wintertraining(15) #8C 题意 求第n(n<2^32)个非完全平方数m,以及\(\sum_{i=1}^m{\lfloor\sqrt i\rfloor}\) ...

  5. 【HDU 2874】Connections between cities(LCA)

    dfs找出所有节点所在树及到树根的距离及深度及父亲. i和j在一棵树上,则最短路为dis[i]+dis[j]-dis[LCA(i,j)]*2. #include <cstring> #in ...

  6. 【HDU - 1257】最少拦截系统(贪心)

    最少拦截系统 Descriptions: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的 ...

  7. 【HDU 5402】Travelling Salesman Problem(构造)

    被某题卡SB了,结果这题也没读好...以为每一个格子能够有负数就当搜索做了.怎么想也搜只是去,后来发现每一个格子是非负数,那么肯定就是构造题. 题解例如以下: 首先假设nn为奇数或者mm为奇数,那么显 ...

  8. 【洛谷】P2725 邮票 Stamps(dp)

    题目背景 给一组 N 枚邮票的面值集合(如,{1 分,3 分})和一个上限 K —— 表示信封上能够贴 K 张邮票.计算从 1 到 M 的最大连续可贴出的邮资. 题目描述 例如,假设有 1 分和 3 ...

  9. [BZOJ2287]【POJ Challenge】消失之物(DP)

    传送门 f[i][j]表示前i个物品,容量为j的方案数c[i][j]表示不选第i个物品,容量为j的方案数两个数组都可以压缩到一维 那么f[i][j] = f[i - 1][j] + f[i - 1][ ...

随机推荐

  1. 【问题解决】访问jhipster-registry-master出现空白页

    问题概述: 刚从github拉下来的jhipster-registry-master直接运行,访问http://localhost:8761会发现会空白页,但是网页的title显示正常,本文目的是解决 ...

  2. 您是哪个等级的CSS开发人员?

    我们在不断的学习,追求进步与提高,到底学到什么程度了,到底是 不是真的了解CSS,是哪个层次了呢.我们来对照一下. 第0级:CSS?那不是一个多人射击游戏吗?  CSS? Isn't that a m ...

  3. 【CodeForces】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  4. 表格标签(table、行、列、表头)

    表格标签 一.<table> <table>代表表格标签.   <table></table> 1.width  表示表格宽度,宽度表达方式有像素和百分 ...

  5. CodeForces - 1016B

    You are given two strings ss and tt, both consisting only of lowercase Latin letters. The substring  ...

  6. 【洛谷 P4166】 [SCOI2007]最大土地面积(凸包,旋转卡壳)

    题目链接 又调了我两个多小时巨亏 直接\(O(n^4)\)枚举4个点显然不行. 数据范围提示我们需要一个\(O(n^2)\)的算法. 于是\(O(n^2)\)枚举对角线,然后在这两个点两边各找一个点使 ...

  7. NYOJ 129 树的判定 (并查集)

    题目链接 描述 A tree is a well-known data structure that is either empty (null, void, nothing) or is a set ...

  8. 22、WebDriver

    什么是WebDriver?1.Webdriver(Selenium2)是一种用于Web应用程序的自动测试工具:2.它提供了一套友好的API:3.Webdriver完全就是一套类库,不依赖任何测试框架, ...

  9. hdu 2063 过山车 二分匹配(匈牙利算法)

    简单题hdu2063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Ot ...

  10. 人脸识别如何做到one-shot learning?(转)

    来源:http://blog.csdn.net/ice_actor/article/details/78603042 1.什么是人脸识别   这部分演示了百度总部大楼的人脸识别系统,员工刷脸进出办公区 ...