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

最新文章

  1. (转)构建自己的AngularJS,第一部分:Scope和Digest
  2. spark示例
  3. JS常用正则表达式和JS控制输入框输入限制(数字、汉字、字符)
  4. Bootstrap学习笔记系列1-------Bootstrap网格系统
  5. 【poj3177】 Redundant Paths
  6. 【转】java环境配置
  7. [转]linux系统的7种运行级别
  8. python爬取某些网站出错的解决办法
  9. 光学字符识别OCR
  10. 神经网络结构在命名实体识别(NER)中的应用
  11. Java对【JSON数据的解析】--官方解析法
  12. 一种更高查询性能的列存储方式MaxMinT 第一部分
  13. JBDC工具类
  14. curl报35错误码
  15. androidpn-client笔记及BUG修改
  16. 保护url时效性和安全性的一种解决方案
  17. jmeter的简单http接口用法
  18. js中实现隐藏部分姓名或者电话号码
  19. html5 datalist 选中option选项后的触发事件
  20. Linux命令(十二)制作静态库和共享库

热门文章

  1. 【Hadoop】用web查看hadoop运行状态
  2. [转]C语言指针详解(经典,非常详细)
  3. 【CodeForces】914 E. Palindromes in a Tree 点分治
  4. oozie与mapreduce简单案例
  5. 【leetcode 简单】第十三题 最大子序和
  6. bzoj 2303 并查集
  7. python作业高级FTP(第八周)
  8. Android中的通信Volley
  9. 011 CountDownLatch,CyclicBarrier和Semaphore
  10. 数据结构与算法之KMP 字符串匹配