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. ArrayList既然继承自AbstractList抽象类,而AbstractList已经实现了List接口,那么ArrayList类为何还要再实现List接口呢?

    https://www.cnblogs.com/bluejavababy/p/4320545.html

  2. Selenium/HtmlUnit设置代理获取JS生成的网页

    通常我们使用Java提供的HttpURLConnection或者Apache的HttpClient获取的网页源代码都是直观可见的,其代码的内容和通过浏览器右键网页->点击查看网页源代码的内容一致 ...

  3. 登入时session的处理方式

    暂时理解不够彻底  有空在详细介绍,先记录代码 1:创建一个工具类  存取当前登录用户 package com.liveyc.eloan.util; import javax.servlet.http ...

  4. HTTP、HTTPS

    http是一种无状态协议,通过短暂保持浏览器核服务器间通信可以有效减少为保持连接而耗费的额外开销.无状态意味着浏览器和服务器完成一次通信后,连接会释放.在下一次会话发起时,浏览器核服务器端不会记录上一 ...

  5. vue-loader 调用了cssLoaders方法配置了css加载器属性。

    module: { loaders: [ // 这里也是相应的配置,test就是匹配文件,loader是加载器, { test: /\.vue$/, loader: 'vue' }, { test: ...

  6. scrapy 爬虫踩过的坑(I)

    问题1:正则表达式没问题,但是爬虫进不了item方法 分析: 1. 可能是下载不到list 页面的内容.可以用 scrapy shell url 进行测试 2. 可能是allowed_domains ...

  7. Ajax请求数据与删除数据后刷新页面

    1.ajax异步请求数据后填入模态框 请求数据的按钮(HTML) <a class="queryA" href="javascript:void(0)" ...

  8. 执行impdp时出现的各种问题

    1.不同的表空间,不同的用户,不同的表名 impdp ODS_YYJC_BUF_ZB/ODS_YYJC_BUF_ZB job_name=bs3 directory=EXPDMP exclude=OBJ ...

  9. vsftpd 安装配置详细教程

    linux下ftp软件不少,大致特点:<br /> wu-ftp:比较老牌,但针对它的攻击比较多,设置比较麻烦,但功能比较强大.<br /> vsftpd:功能强大,配置也比较 ...

  10. linux自动创建dev node

    通过驱动模块的加载在/dev下创建设备文件,在驱动模块卸载时又自动的删除在/dev下创建的设备文件非常方便.而这个过程就是通过device_create()和device_destroy()内核函数完 ...