机器人的比赛的一个算法问题,用到排列数,怎么用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
javascript如何用数组实现冒泡排序的算法,不用sort函数怎么实现?
1
java附加条件的组合数算法
1
机器人逆运动学神经网络算法
2
一个C语言算法实际的问题,怎么实现
1
一个排列的算法的问题是用的C语言实现
2
一个c语言的算法循环问题
1
组合数的排列算法问题,请问这里的序列怎么得到,用C语言。。。
1
机器人的位置移动的问题,用C语言编写算法解决,谢谢
1
一个有关机器人的算法的问题,求助各位坛友,采用C语言
2
排列组合的算法的问题,C语言实现,要求从中选出m件物品的排列数。
1
数据结构上的一个线性表的冲突的解决,是不是用哈希算法怎么采用C语言的实现方式
0
排列组合的算法问题,同时也是一个数组的问题,怎么使用C语言程序
0
树状节点的编号的一个算法的问题,看下怎么使用C语言编写程序来计算
2
c++数组算法问题数组元素
0
集合的匹配的一个算法问题的解释?如何利用C语言实现的
0
字母的排列构成的单词的算法的问题,是如何利用C语言的办法实现呢
0
方块在网格里的排列的算法问题,这个问题的C语言编程的解答的方式
0
一个歇后语和程序的对照计算的算法问题的解决,怎么才能使用C程序的语言的设计的代码来计算的
0
数字连乘的一个算法问题,循环的计算用C语言的程序设计的办法
0
字母序列的排列和连接的问题,怎么使用C语言的办法来实现算法的求解