编程介的小学生 2019-04-18 22:46 采纳率: 20.5%
浏览 184

机器人的比赛的一个算法问题,用到排列数,怎么用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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!