输出序列开头的元素的做法,利用C语言的程序的射击的语言的方式

Problem Description

Do you still remember the movie "I, robot" ? In that movie, Sunny is a very special, unique robot who can dream! As we known, robot is a machine installed with artificial intelligence, and it can't response to the situations which are not contained in the pre-designed programs. But the creator of Sunny detects that the logic sequences existed in the robot would change under some particular cases, e.g. magnetic field, noises etc. He called this unpredictable sequence ghosts in the robot because these random combination of 1s and 0 s could yield unpredictable behaviors of robots, it was terrible! In order to detect this situation as soon as possible, you should help the prof. via your outstanding programming skills.
You would be given a sequence with the length of N, and this sequence is only contained 0 and 1.Based on the professor's recent research data, the sequence could have at most F successive bits flipped(that means 0 changes to 1, and 1 changes to 0) and could have at most R successive bits remained the same. Based on these situations, you should calculate the maximum number of 1 in the sequence after those changes.

Input
The input would have multiple test cases, each test case has two lines, The first line contains two integer R and F(1 <= R <= 50, 1 <= F <= 50), indicating the number of the digits remain the same and the number of the digits flipped respectively. the second line is a sequence only comprises of 0 and 1, whose length is between 1 and 1000.The input would end when R == 0 and F == 0.

Output
For each case, print a line with the maximum number of 1 left in the sequence.

Sample Input
4 1
1111
2 2
1111
0 0

Sample Output
4
3

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

4
交换二叉树中每个结点的左孩子和右孩子C++语言
13
c语言编译的最大子序列求和问题
2
C语言输出格雷码的问题
1
定序列A={A1,A2,...,An}, 要求改变序列A中的某些元素,形成一个严格单调的序列B
2
给一个整数x将该数插入到序列中,并使新的序列仍然有序,如何C语言
1
C程序输出题目所要求的序列,序列中每个元素一行。如果存在两个符合要求的序列
1
一个用C语言进行偶数求和的复习题,对于每组输入数据,输出一个平均值序列,每组输出占一行。
0
给一个整数x,请将该数插入到序列中,并使新的序列仍然有序,使用C语言怎么实现的计算
0
请问这个选择优化的算法问题输出序列如何是利用C语言的技术?
0
最大二进制公共子序列的一个算法的问题如何利用C语言的办法去实现怎么做?
0
两个字符串序列的比较的问题,如何利用C语言的方式怎么解决
0
两个连续子序列的匹配的问题,利用C语言的办法怎么实现的呢?
2
以实际数量求平均值。编程输出该平均值序列,采用C语言编程实现
0
寻找集合的非递减序列的算法,怎么利用C语言程序的设计办法来实现的
0
请问这个程序用c怎么写?什么时候输出的序列不是单调递增?
2
使用phtread多线程编程程序来生成Fibonacci序列 c/c++
0
如何重复输出这里的数字的序列的,采用C程序的语言的设计的办法
0
真假数的序列的一个判断的算法,怎么用C语言的程序的设计的方式实现
0
最终的序列的计算,网格搜索的一个算法,怎么利用C语言的程序的技术实现的
0
单调增长的子序列的一个算法题,要求利用C语言的程序编写的思想来实现怎么做